react-native-navigation的迁移库

Navigation.test.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. describe('Navigation', () => {
  2. let Navigation;
  3. beforeEach(() => {
  4. //TODO don't mock here, just create the actual object and assert on basic behavior
  5. jest.mock('./adapters/UniqueIdProvider');
  6. jest.mock('./adapters/NativeCommandsSender');
  7. jest.mock('./adapters/NativeEventsReceiver');
  8. jest.mock('./containers/ContainerRegistry');
  9. jest.mock('./commands/AppCommands');
  10. Navigation = require('./Navigation').default;
  11. });
  12. it('registerContainer delegates to ContainerRegistry', () => {
  13. expect(Navigation.containerRegistry.registerContainer).not.toHaveBeenCalled();
  14. const fn = jest.fn();
  15. Navigation.registerContainer('name', fn);
  16. expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledTimes(1);
  17. expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledWith('name', fn);
  18. });
  19. it('setRoot delegates to Commands', async () => {
  20. Navigation.appCommands.setRoot.mockReturnValue(Promise.resolve('result'));
  21. const params = {};
  22. const result = await Navigation.setRoot(params);
  23. expect(result).toEqual('result');
  24. expect(Navigation.appCommands.setRoot).toHaveBeenCalledTimes(1);
  25. expect(Navigation.appCommands.setRoot).toHaveBeenCalledWith(params);
  26. });
  27. it('events return public events', () => {
  28. const cb = jest.fn();
  29. Navigation.events().onAppLaunched(cb);
  30. expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledTimes(1);
  31. expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledWith(cb);
  32. });
  33. it('on containerId returns an object that performs commands on a container', () => {
  34. expect(Navigation.on('myUniqueId').push).toBeInstanceOf(Function);
  35. });
  36. it('starts listening and handles internal events', () => {
  37. expect(Navigation.nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
  38. });
  39. });