|
1 | | -const mockedNavigation: any = { |
2 | | - addListener: jest.fn(), |
3 | | - closeDrawer: jest.fn(), |
4 | | - dangerouslyGetParent: jest.fn(), |
5 | | - dismiss: jest.fn(), |
6 | | - dispatch: jest.fn(), |
7 | | - getParam: jest.fn(), |
8 | | - goBack: jest.fn(), |
9 | | - isFocused: jest.fn(), |
10 | | - navigate: jest.fn(), |
11 | | - openDrawer: jest.fn(), |
12 | | - pop: jest.fn(), |
13 | | - popToTop: jest.fn(), |
14 | | - push: jest.fn(), |
15 | | - replace: jest.fn(), |
16 | | - setParams: jest.fn(), |
17 | | - toggleDrawer: jest.fn(), |
18 | | -}; |
19 | | - |
20 | | -const mockedRoute = { |
21 | | - index: 0, |
22 | | - isTransitioning: false, |
23 | | - key: 'kjdkj', |
24 | | - name: 'Home', |
25 | | - params: { foo: 'bar' }, |
26 | | - path: '/', |
27 | | - routes: [ |
28 | | - { |
29 | | - index: 1, |
30 | | - isTransitioning: false, |
31 | | - key: 'jsdfl', |
32 | | - path: '/settings', |
33 | | - routeName: 'Settings', |
34 | | - routes: [], |
35 | | - }, |
36 | | - ], |
37 | | -}; |
38 | | - |
39 | | -jest.mock('@react-navigation/native', () => { |
40 | | - const actual = jest.requireActual('@react-navigation/native'); |
41 | | - return { |
42 | | - ...actual, |
43 | | - |
44 | | - useNavigation: () => mockedNavigation, |
45 | | - useRoute: () => mockedRoute, |
46 | | - }; |
47 | | -}); |
48 | | - |
49 | 1 | import { NavigationActions } from '../NavigationActions'; |
| 2 | +import { NavigationContext } from '@bluebase/core'; |
50 | 3 | import React from 'react'; |
51 | 4 | import { mount } from 'enzyme'; |
52 | 5 |
|
53 | 6 | describe('NavigationActions tests', () => { |
54 | 7 | it('should check props', async () => { |
55 | 8 | const children = jest.fn().mockReturnValue(null); |
56 | | - |
57 | | - mount(<NavigationActions>{children}</NavigationActions>); |
| 9 | + const nav: any = { |
| 10 | + state: { |
| 11 | + name: 'Home', |
| 12 | + params: { foo: 'bar' }, |
| 13 | + path: '/', |
| 14 | + }, |
| 15 | + }; |
| 16 | + |
| 17 | + mount( |
| 18 | + <NavigationContext.Provider value={nav}> |
| 19 | + <NavigationActions>{children}</NavigationActions> |
| 20 | + </NavigationContext.Provider> |
| 21 | + ); |
58 | 22 |
|
59 | 23 | expect(children).toHaveBeenCalledTimes(1); |
60 | 24 |
|
61 | 25 | const result = children.mock.calls[0][0]; |
62 | | - expect(result.state.key).toBe('kjdkj'); |
63 | | - expect(result.state.routeName).toBe('Home'); |
64 | | - expect(result.state.params).toMatchObject({ foo: 'bar' }); |
65 | | - expect(result.source).toBeTruthy(); |
| 26 | + expect(result).toMatchObject(nav); |
66 | 27 | }); |
67 | 28 | }); |
0 commit comments