1 | import DeviceMotion from '../DeviceMotion';
|
2 | import ExponentDeviceMotion from '../ExponentDeviceMotion';
|
3 |
|
4 | afterEach(() => {
|
5 | DeviceMotion.removeAllListeners();
|
6 | });
|
7 |
|
8 | it(`adds an "deviceMotionDidUpdate" listener`, () => {
|
9 | const NativeDeviceMotion = ExponentDeviceMotion;
|
10 |
|
11 | const mockListener = jest.fn();
|
12 | const subscription = DeviceMotion.addListener(mockListener);
|
13 |
|
14 | expect(NativeDeviceMotion.addListener).toHaveBeenCalledTimes(1);
|
15 | expect(NativeDeviceMotion.addListener).toHaveBeenCalledWith('deviceMotionDidUpdate');
|
16 |
|
17 | subscription.remove();
|
18 | expect(NativeDeviceMotion.removeListeners).toHaveBeenCalledTimes(1);
|
19 | expect(NativeDeviceMotion.removeListeners).toHaveBeenCalledWith(1);
|
20 | });
|
21 |
|
22 | it(`notifies listeners`, () => {
|
23 | const mockListener = jest.fn();
|
24 | DeviceMotion.addListener(mockListener);
|
25 |
|
26 | const mockEvent = { x: 0.2, y: 0.1, z: 0.3 };
|
27 | DeviceMotion._nativeEmitter.emit('deviceMotionDidUpdate', mockEvent);
|
28 | expect(mockListener).toHaveBeenCalledWith(mockEvent);
|
29 | });
|