react-native-navigation的迁移库

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const React = require('react');
  2. require('react-native');
  3. const renderer = require('react-test-renderer');
  4. const { Navigation } = require('../../lib/dist/index');
  5. describe('remx support', () => {
  6. let MyConnectedComponent;
  7. let store;
  8. beforeEach(() => {
  9. MyConnectedComponent = require('./MyComponent');
  10. store = require('./MyStore');
  11. });
  12. it('renders normally', () => {
  13. const tree = renderer.create(<MyConnectedComponent />);
  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(<MyConnectedComponent 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', () => {
  27. const renderCountIncrement = jest.fn();
  28. const tree = renderer.create(<MyConnectedComponent 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. it('support for static members in connected components', () => {
  37. expect(MyConnectedComponent.options).toEqual({ title: 'MyComponent' });
  38. const registeredComponentClass = Navigation.registerComponent('MyComponentName', () => MyConnectedComponent);
  39. expect(registeredComponentClass.options).toEqual({ title: 'MyComponent' });
  40. });
  41. });