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