SHARE
TWEET

Untitled

a guest Apr 20th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react';
  2. import * as TestRenderer from 'react-test-renderer';
  3. import TestClass from '../TestClass';
  4. import TestHoc from '../TestHoc';
  5.  
  6. let renderer: TestRenderer.ReactTestRenderer;
  7.  
  8. describe("Test Component state change without HOC", () => {
  9.   beforeAll(() => {
  10.     renderer = TestRenderer.create(
  11.       <TestClass />
  12.     );
  13.   });
  14.  
  15.   it("should have counter element", () => {
  16.     let root = renderer.root;
  17.     const counter = root.findAll(
  18.       (el) => el.props.testID === 'counter' && el.type === 'Text'
  19.     );
  20.     expect(counter).toHaveLength(1);
  21.   });
  22.  
  23.   it("should count 0 as a default", () => {
  24.     let root = renderer.root;
  25.     const counter = root.findAll(
  26.       (el) => el.props.testID === 'counter' && el.type === 'Text'
  27.     );
  28.     expect(counter[0].children).toEqual(['0']);
  29.   });
  30.  
  31.   it("should setState the counter to 1", () => {
  32.     let root = renderer.root;
  33.     const instance = root.instance;
  34.     instance.setState({ count: 1 })
  35.     const counter = root.findAll(
  36.       (el) => el.props.testID === 'counter' && el.type === 'Text'
  37.     );
  38.     expect(counter[0].children).toEqual(['1']);
  39.   });
  40. });
  41.  
  42. describe('Set preps With HOC', () => {
  43.  
  44.   it("should preset counter to 2", () => {
  45.     const CountFactory = TestHoc({ count: 2 })(TestClass);  
  46.     renderer = TestRenderer.create(
  47.       <CountFactory />
  48.     );
  49.  
  50.     let root = renderer.root;
  51.     const counter = root.findAll(
  52.       (el) => el.props.testID === 'counter' && el.type === 'Text'
  53.     );
  54.     expect(counter[0].children).toEqual(['2']);
  55.   });
  56.  
  57. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top