diff --git a/Mock.ts b/Mock.ts new file mode 100644 index 00000000000..c4cbf00d1c0 --- /dev/null +++ b/Mock.ts @@ -0,0 +1 @@ +export * from './lib/dist/Mock'; diff --git a/jest-setup.js b/jest-setup.js index 23a79cc85d0..1cd3444f44d 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -3,11 +3,11 @@ const { mockDetox } = require('detox-testing-library-rnn-adapter'); mockDetox(() => require('./playground/index')); beforeEach(() => { - const { Navigation } = require('react-native-navigation'); + const { mockNativeComponents } = require('react-native-navigation/Mock'); setTimeout = (func) => { func(); }; - Navigation.mockNativeComponents(); + mockNativeComponents(); mockUILib(); }); diff --git a/lib/src/Mock/index.ts b/lib/src/Mock/index.ts index 853604d556e..30e553ea08d 100644 --- a/lib/src/Mock/index.ts +++ b/lib/src/Mock/index.ts @@ -1,3 +1,16 @@ export const ApplicationMock = require('./Application').Application; export * from './constants'; + +export function mockNativeComponents() { + const { NativeCommandsSender } = require('./mocks/NativeCommandsSender'); + const { NativeEventsReceiver } = require('./mocks/NativeEventsReceiver'); + const { AppRegistryService } = require('./mocks/AppRegistryService'); + const { Navigation } = require('react-native-navigation'); + + Navigation.mockNativeComponents( + new NativeCommandsSender(), + new NativeEventsReceiver(), + new AppRegistryService() + ); +} diff --git a/lib/src/NavigationDelegate.ts b/lib/src/NavigationDelegate.ts index da06c18f3e8..90aecf18a88 100644 --- a/lib/src/NavigationDelegate.ts +++ b/lib/src/NavigationDelegate.ts @@ -226,14 +226,15 @@ export class NavigationDelegate { return this.concreteNavigation.TouchablePreview; } - public mockNativeComponents() { - const { NativeCommandsSender } = require('./Mock/mocks/NativeCommandsSender'); - const { NativeEventsReceiver } = require('./Mock/mocks/NativeEventsReceiver'); - const { AppRegistryService } = require('./Mock/mocks/AppRegistryService'); + public mockNativeComponents( + mockedNativeCommandsSender: NativeCommandsSender, + mockedNativeEventsReceiver: NativeEventsReceiver, + mockedAppRegistryService: AppRegistryService + ) { this.concreteNavigation = this.createConcreteNavigation( - new NativeCommandsSender(), - new NativeEventsReceiver(), - new AppRegistryService() + mockedNativeCommandsSender, + mockedNativeEventsReceiver, + mockedAppRegistryService ); } diff --git a/lib/src/index.ts b/lib/src/index.ts index 006cee09dbb..8a44e8aa9e6 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -16,4 +16,3 @@ export * from './interfaces/NavigationFunctionComponent'; export * from './interfaces/CommandName'; export * from './interfaces/Processors'; export * from './interfaces/ProcessorSubscription'; -export * from './Mock'; diff --git a/package.json b/package.json index 9552bc3ce47..2d700225f97 100644 --- a/package.json +++ b/package.json @@ -115,8 +115,8 @@ "ts-mockito": "^2.3.1", "typedoc": "0.x.x", "typescript": "3.9.5", - "detox-testing-library-rnn-adapter": "1.x.x", - "remx": "4.x.x" + "detox-testing-library-rnn-adapter": "2.x.x", + "remx": "3.x.x" }, "jest": { "preset": "react-native", @@ -134,6 +134,7 @@ "./jest-setup.js" ], "moduleNameMapper": { + "react-native-navigation/Mock": "/lib/src/Mock", "react-native-navigation": "/lib/src", "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/playground/img/layouts@2x.png" }, @@ -257,4 +258,4 @@ } } } -} \ No newline at end of file +}