react-native-navigation的迁移库

PrivateEventsListener.test.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import _ from 'lodash';
  2. import PrivateEventsListener from './PrivateEventsListener';
  3. import NativeEventsReceiver from '../adapters/NativeEventsReceiver.mock';
  4. import Store from '../containers/Store';
  5. describe('PrivateEventsListener', () => {
  6. let uut;
  7. let nativeEventsReceiver;
  8. let store;
  9. beforeEach(() => {
  10. nativeEventsReceiver = new NativeEventsReceiver();
  11. store = new Store();
  12. uut = new PrivateEventsListener(nativeEventsReceiver, store);
  13. });
  14. it('register and handle containerStart', () => {
  15. const mockRef = {
  16. onStart: jest.fn()
  17. };
  18. store.setRefForId('myContainerId', mockRef);
  19. uut.listenAndHandlePrivateEvents();
  20. expect(nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
  21. const callbackFunction = nativeEventsReceiver.containerStart.mock.calls[0][0];
  22. expect(callbackFunction).toBeInstanceOf(Function);
  23. expect(mockRef.onStart).not.toHaveBeenCalled();
  24. callbackFunction('myContainerId');
  25. expect(mockRef.onStart).toHaveBeenCalledTimes(1);
  26. });
  27. it('register and listen containerStop', () => {
  28. uut.listenAndHandlePrivateEvents();
  29. expect(nativeEventsReceiver.containerStop).toHaveBeenCalledTimes(1);
  30. });
  31. });