react-native-navigation的迁移库

remx.test.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require('react-native');
  2. import React from 'react';
  3. import renderer from 'react-test-renderer';
  4. describe('remx support', () => {
  5. let MyConnectedContainer;
  6. let store;
  7. beforeEach(() => {
  8. MyConnectedContainer = require('./component').default;
  9. store = require('./store');
  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 tree = renderer.create(<MyConnectedContainer/>);
  17. const instance = tree.getInstance();
  18. expect(tree.toJSON().children).toEqual(['no name']);
  19. expect(instance.renders).toEqual(1);
  20. store.mutators.setName('Bob');
  21. expect(store.selectors.getName()).toEqual('Bob');
  22. expect(tree.toJSON().children).toEqual(['Bob']);
  23. expect(instance.renders).toEqual(2);
  24. });
  25. it('rerenders as a result of an underlying state change with a new key using merge', () => {
  26. const tree = renderer.create(<MyConnectedContainer printAge={true}/>);
  27. const instance = tree.getInstance();
  28. expect(tree.toJSON().children).toEqual(null);
  29. expect(instance.renders).toEqual(1);
  30. store.mutators.setAge(30);
  31. expect(store.selectors.getAge()).toEqual(30);
  32. expect(tree.toJSON().children).toEqual([30]);
  33. expect(instance.renders).toEqual(2);
  34. });
  35. });