react-native-navigation的迁移库

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const React = require('react');
  2. require('react-native');
  3. const renderer = require('react-test-renderer');
  4. describe('remx support', () => {
  5. let MyConnectedContainer;
  6. let store;
  7. beforeEach(() => {
  8. MyConnectedContainer = require('./MyContainer');
  9. store = require('./MyStore');
  10. });
  11. it('renders normally', () => {
  12. const tree = renderer.create(<MyConnectedContainer />);
  13. expect(tree.toJSON().children).toEqual(['no name']);
  14. });
  15. it('rerenders as a result of an underlying state change (by selector)', () => {
  16. const renderCountIncrement = jest.fn();
  17. const tree = renderer.create(<MyConnectedContainer renderCountIncrement={renderCountIncrement} />);
  18. expect(tree.toJSON().children).toEqual(['no name']);
  19. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  20. store.setters.setName('Bob');
  21. expect(store.getters.getName()).toEqual('Bob');
  22. expect(tree.toJSON().children).toEqual(['Bob']);
  23. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  24. });
  25. it('rerenders as a result of an underlying state change with a new key', () => {
  26. const renderCountIncrement = jest.fn();
  27. const tree = renderer.create(<MyConnectedContainer printAge={true} renderCountIncrement={renderCountIncrement} />);
  28. expect(tree.toJSON().children).toEqual(null);
  29. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  30. store.setters.setAge(30);
  31. expect(store.getters.getAge()).toEqual(30);
  32. expect(tree.toJSON().children).toEqual(['30']);
  33. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  34. });
  35. });