react-native-navigation的迁移库

Lifecycle.test.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const Lifecycle = require('./Lifecycle');
  2. const Store = require('../containers/Store');
  3. describe('Lifecycle', () => {
  4. let store;
  5. let uut;
  6. let mockRef;
  7. beforeEach(() => {
  8. mockRef = {
  9. didAppear: jest.fn(),
  10. didDisappear: jest.fn(),
  11. onNavigationButtonPressed: jest.fn()
  12. };
  13. store = new Store();
  14. store.setRefForContainerId('myUniqueId', mockRef);
  15. uut = new Lifecycle(store);
  16. });
  17. describe('containerDidAppear', () => {
  18. it('calls didAppear on container ref from store', () => {
  19. uut.containerDidAppear('myUniqueId');
  20. expect(mockRef.didAppear).toHaveBeenCalledTimes(1);
  21. });
  22. it('skips undefined refs', () => {
  23. uut.containerDidAppear('myUniqueId2');
  24. expect(mockRef.didAppear).not.toHaveBeenCalled();
  25. });
  26. it('skips unimplemented didAppear', () => {
  27. mockRef = {};
  28. expect(mockRef.didAppear).toBeUndefined();
  29. store.setRefForContainerId('myUniqueId', mockRef);
  30. uut.containerDidAppear('myUniqueId');
  31. });
  32. });
  33. describe('containerDidDisappear', () => {
  34. it('calls didDisappear on container ref from store', () => {
  35. uut.containerDidDisappear('myUniqueId');
  36. expect(mockRef.didDisappear).toHaveBeenCalledTimes(1);
  37. });
  38. it('skips undefined refs', () => {
  39. uut.containerDidDisappear('myUniqueId2');
  40. expect(mockRef.didDisappear).not.toHaveBeenCalled();
  41. });
  42. it('skips unimplemented didDisappear', () => {
  43. mockRef = {};
  44. expect(mockRef.didDisappear).toBeUndefined();
  45. store.setRefForContainerId('myUniqueId', mockRef);
  46. uut.containerDidDisappear('myUniqueId');
  47. });
  48. });
  49. describe('onNavigationButtonPressed', () => {
  50. it('calls onNavigationButtonPressed on container ref from store', () => {
  51. uut.onNavigationButtonPressed({
  52. containerId: 'myUniqueId',
  53. buttonId: 'myButtonId'
  54. });
  55. expect(mockRef.onNavigationButtonPressed).toHaveBeenCalledTimes(1);
  56. });
  57. it('skips undefined refs', () => {
  58. uut.onNavigationButtonPressed('myButtonId');
  59. expect(mockRef.didDisappear).not.toHaveBeenCalled();
  60. });
  61. it('skips unimplemented onNavigationButtonPressed', () => {
  62. mockRef = {};
  63. expect(mockRef.onNavigationButtonPressed).toBeUndefined();
  64. store.setRefForContainerId('myUniqueId', mockRef);
  65. uut.containerDidAppear('myUniqueId');
  66. });
  67. });
  68. });