Created
April 10, 2019 16:10
-
-
Save goodpic/7d316e25ab866abb6837e47f7192e333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import * as TestRenderer from 'react-test-renderer'; | |
import TestClass from '../TestClass'; | |
import TestHoc from '../TestHoc'; | |
let renderer: TestRenderer.ReactTestRenderer; | |
describe("Test Component state change without HOC", () => { | |
beforeAll(() => { | |
renderer = TestRenderer.create( | |
<TestClass /> | |
); | |
}); | |
it("should have counter element", () => { | |
let root = renderer.root; | |
const counter = root.findAll( | |
(el) => el.props.testID === 'counter' && el.type === 'Text' | |
); | |
expect(counter).toHaveLength(1); | |
}); | |
it("should count 0 as a default", () => { | |
let root = renderer.root; | |
const counter = root.findAll( | |
(el) => el.props.testID === 'counter' && el.type === 'Text' | |
); | |
expect(counter[0].children).toEqual(['0']); | |
}); | |
it("should setState the counter to 1", () => { | |
let root = renderer.root; | |
const instance = root.instance; | |
instance.setState({ count: 1 }) | |
const counter = root.findAll( | |
(el) => el.props.testID === 'counter' && el.type === 'Text' | |
); | |
expect(counter[0].children).toEqual(['1']); | |
}); | |
}); | |
describe('Set preps With HOC', () => { | |
it("should preset counter to 2", () => { | |
const CountFactory = TestHoc({ count: 2 })(TestClass); | |
renderer = TestRenderer.create( | |
<CountFactory /> | |
); | |
let root = renderer.root; | |
const counter = root.findAll( | |
(el) => el.props.testID === 'counter' && el.type === 'Text' | |
); | |
expect(counter[0].children).toEqual(['2']); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment