react-native-navigation的迁移库

ContainerRegistry.test.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { Component } from 'react';
  2. import { AppRegistry, Text } from 'react-native';
  3. import renderer from 'react-test-renderer';
  4. import ContainerRegistry from './ContainerRegistry';
  5. import Store from './Store';
  6. describe('ContainerRegistry', () => {
  7. let uut;
  8. let store;
  9. class MyContainer extends Component {
  10. render() {
  11. return <Text>{'Hello, World!'}</Text>;
  12. }
  13. }
  14. beforeEach(() => {
  15. store = new Store();
  16. AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
  17. uut = new ContainerRegistry(store);
  18. });
  19. it('registers container component by containerName into AppRegistry', () => {
  20. expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
  21. uut.registerContainer('example.MyContainer.name', () => MyContainer);
  22. expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
  23. expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer.name');
  24. });
  25. it('saves the original container into the store', () => {
  26. expect(store.getOriginalContainerClassForName('example.MyContainer.name')).toBeUndefined();
  27. uut.registerContainer('example.MyContainer.name', () => MyContainer);
  28. const Class = store.getOriginalContainerClassForName('example.MyContainer.name');
  29. expect(Class).not.toBeUndefined();
  30. expect(Class).toEqual(MyContainer);
  31. expect(Object.getPrototypeOf(Class)).toEqual(Component);
  32. });
  33. it('resulting in a normal component', () => {
  34. uut.registerContainer('example.MyContainer.name', () => MyContainer);
  35. const Container = AppRegistry.registerComponent.mock.calls[0][1]();
  36. const tree = renderer.create(<Container id="123" />);
  37. expect(tree.toJSON().children).toEqual(['Hello, World!']);
  38. });
  39. });