const React = require('react'); const { Component } = require('react'); const { AppRegistry, Text } = require('react-native'); const renderer = require('react-test-renderer'); const ContainerRegistry = require('./ContainerRegistry'); const Store = require('./Store'); describe('ContainerRegistry', () => { let uut; let store; class MyContainer extends Component { render() { return {'Hello, World!'}; } } beforeEach(() => { store = new Store(); AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent); uut = new ContainerRegistry(store); }); it('registers container component by containerName into AppRegistry', () => { expect(AppRegistry.registerComponent).not.toHaveBeenCalled(); uut.registerContainer('example.MyContainer.name', () => MyContainer); expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1); expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer.name'); }); it('saves the original container into the store', () => { expect(store.getOriginalContainerClassForName('example.MyContainer.name')).toBeUndefined(); uut.registerContainer('example.MyContainer.name', () => MyContainer); const Class = store.getOriginalContainerClassForName('example.MyContainer.name'); expect(Class).not.toBeUndefined(); expect(Class).toEqual(MyContainer); expect(Object.getPrototypeOf(Class)).toEqual(Component); }); it('resulting in a normal component', () => { uut.registerContainer('example.MyContainer.name', () => MyContainer); const Container = AppRegistry.registerComponent.mock.calls[0][1](); const tree = renderer.create(); expect(tree.toJSON().children).toEqual(['Hello, World!']); }); });