react-native-navigation的迁移库

Navigation.test.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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('showModal delegates to AppCommands', async () => {
  28. Navigation.appCommands.showModal.mockReturnValue(Promise.resolve('result'));
  29. const params = {};
  30. const result = await Navigation.showModal(params);
  31. expect(result).toEqual('result');
  32. expect(Navigation.appCommands.showModal).toHaveBeenCalledTimes(1);
  33. expect(Navigation.appCommands.showModal).toHaveBeenCalledWith(params);
  34. });
  35. it('dismissModal delegates to AppCommands', async () => {
  36. Navigation.appCommands.dismissModal.mockReturnValue(Promise.resolve('result'));
  37. const params = {};
  38. const result = await Navigation.dismissModal(params);
  39. expect(result).toEqual('result');
  40. expect(Navigation.appCommands.dismissModal).toHaveBeenCalledTimes(1);
  41. expect(Navigation.appCommands.dismissModal).toHaveBeenCalledWith(params);
  42. });
  43. it('events return public events', () => {
  44. const cb = jest.fn();
  45. Navigation.events().onAppLaunched(cb);
  46. expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledTimes(1);
  47. expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledWith(cb);
  48. });
  49. it('on containerId returns an object that performs commands on a container', () => {
  50. expect(Navigation.on('myUniqueId').push).toBeInstanceOf(Function);
  51. });
  52. it('starts listening and handles internal events', () => {
  53. expect(Navigation.nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
  54. });
  55. it('dismissAllModals', async () => {
  56. Navigation.appCommands.dismissAllModals.mockReturnValue(Promise.resolve('result'));
  57. const result = await Navigation.dismissAllModals();
  58. expect(Navigation.appCommands.dismissAllModals).toHaveBeenCalledTimes(1);
  59. expect(result).toEqual('result');
  60. });
  61. });