react-native-navigation的迁移库

ContainerRegistry.test.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {AppRegistry, Text} from 'react-native';
  2. import React, {Component} from 'react';
  3. class MyContainer extends Component {
  4. render() {
  5. return (
  6. <Text>{'Hello, World!'}</Text>
  7. );
  8. }
  9. }
  10. import renderer from 'react-test-renderer';
  11. describe('ComponentRegistry', () => {
  12. let uut;
  13. beforeEach(() => {
  14. AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
  15. //jest.mock('react-native', () => ({AppRegistry}));
  16. uut = require('./ContainerRegistry');
  17. });
  18. xit('registers container component into AppRegistry', () => {
  19. expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
  20. uut.registerContainer('example.MyContainer', () => MyContainer);
  21. expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
  22. expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer');
  23. });
  24. it('wraps the container', () => {
  25. uut.registerContainer('example.MyContainer', () => MyContainer);
  26. const WrappedClass = AppRegistry.registerComponent.mock.calls[0][1]();
  27. const tree = renderer.create(
  28. <WrappedClass/>
  29. );
  30. console.log(tree.toJSON())
  31. });
  32. });