react-native-navigation的迁移库

remx.test.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. jest.resetModules();
  9. MyConnectedContainer = require('./component').default;
  10. store = require('./store');
  11. });
  12. it('renders normally', () => {
  13. const tree = renderer.create(<MyConnectedContainer />);
  14. expect(tree.toJSON().children).toEqual(['no name']);
  15. });
  16. it('rerenders as a result of an underlying state change (by selector)', () => {
  17. const renderCountIncrement = jest.fn();
  18. const tree = renderer.create(<MyConnectedContainer renderCountIncrement={renderCountIncrement} />);
  19. expect(tree.toJSON().children).toEqual(['no name']);
  20. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  21. store.setters.setName('Bob');
  22. expect(store.getters.getName()).toEqual('Bob');
  23. expect(tree.toJSON().children).toEqual(['Bob']);
  24. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  25. });
  26. it('rerenders as a result of an underlying state change with a new key using merge', () => {
  27. const renderCountIncrement = jest.fn();
  28. const tree = renderer.create(<MyConnectedContainer printAge={true} renderCountIncrement={renderCountIncrement} />);
  29. expect(tree.toJSON().children).toEqual(null);
  30. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  31. store.setters.setAge(30);
  32. expect(store.getters.getAge()).toEqual(30);
  33. expect(tree.toJSON().children).toEqual(['30']);
  34. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  35. });
  36. });