mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-18 04:42:45 +00:00
@@ -10,23 +10,10 @@ describe('apis/AppState', () => {
|
||||
expect(() => AppState.addEventListener('foo', handler)).toThrow();
|
||||
expect(() => AppState.addEventListener('change', handler).remove()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeEventListener', () => {
|
||||
beforeEach(() => {
|
||||
// removeEventListener logs a deprecation warning, ignore
|
||||
jest.spyOn(console, 'error');
|
||||
console.error.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
console.error.mockRestore();
|
||||
});
|
||||
|
||||
test('throws if the provided "eventType" is not supported', () => {
|
||||
AppState.addEventListener('change', handler);
|
||||
expect(() => AppState.removeEventListener('foo', handler)).toThrow();
|
||||
expect(() => AppState.removeEventListener('change', handler)).not.toThrow();
|
||||
test('returns remove subscription', () => {
|
||||
const subscription = AppState.addEventListener('change', handler);
|
||||
expect(() => subscription.remove()).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,6 +72,11 @@ export default class AppState {
|
||||
|
||||
static removeEventListener(type: string, handler: Function) {
|
||||
if (AppState.isAvailable) {
|
||||
console.error(
|
||||
`AppState.removeListener('${type}', ...): Method has been ` +
|
||||
'deprecated. Please instead use `remove()` on the subscription ' +
|
||||
'returned by `AppState.addEventListener`.'
|
||||
);
|
||||
invariant(
|
||||
EVENT_TYPES.indexOf(type) !== -1,
|
||||
'Trying to remove listener for unknown event: "%s"',
|
||||
|
||||
Reference in New Issue
Block a user