-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
eventHandler.test.ts
25 lines (21 loc) · 976 Bytes
/
eventHandler.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// addEventHandler and removeEventHandler are provided in the ./index
import {addEventHandler, removeEventHandler} from '../index';
// dispatch comes from the ./state
import {dispatch} from '../state';
test('addEventHandler and removeEventHandler control handlers', async () => {
const spy = jest.fn();
addEventHandler(spy);
expect(spy).not.toHaveBeenCalledWith({name: 'unknown1'}, expect.anything());
await dispatch({name: 'unknown1' as any});
expect(spy).toHaveBeenCalledWith({name: 'unknown1'}, expect.anything());
removeEventHandler(spy);
expect(spy).not.toHaveBeenCalledWith({name: 'unknown2'}, expect.anything());
await dispatch({name: 'unknown2' as any});
expect(spy).not.toHaveBeenCalledWith({name: 'unknown2'}, expect.anything());
});