react-native-navigation的迁移库

remx.test.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. require('react-native');
  3. import renderer from '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. const instance = tree.getInstance();
  20. expect(tree.toJSON().children).toEqual(['no name']);
  21. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  22. store.setters.setName('Bob');
  23. expect(store.getters.getName()).toEqual('Bob');
  24. expect(tree.toJSON().children).toEqual(['Bob']);
  25. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  26. });
  27. it('rerenders as a result of an underlying state change with a new key using merge', () => {
  28. const renderCountIncrement = jest.fn();
  29. const tree = renderer.create(<MyConnectedContainer printAge={true} renderCountIncrement={renderCountIncrement} />);
  30. const instance = tree.getInstance();
  31. expect(tree.toJSON().children).toEqual(null);
  32. expect(renderCountIncrement).toHaveBeenCalledTimes(1);
  33. store.setters.setAge(30);
  34. expect(store.getters.getAge()).toEqual(30);
  35. expect(tree.toJSON().children).toEqual([30]);
  36. expect(renderCountIncrement).toHaveBeenCalledTimes(2);
  37. });
  38. });