react-native-navigation的迁移库

ContainerRegistry.test.js 1.8KB

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