Skip to content

Commit

Permalink
feat: test config and first suite
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-zy committed May 20, 2018
1 parent 4089041 commit ff57c5a
Show file tree
Hide file tree
Showing 5 changed files with 546 additions and 13 deletions.
12 changes: 0 additions & 12 deletions __tests__/App.js

This file was deleted.

40 changes: 40 additions & 0 deletions __tests__/components/OrientationHOC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'react-native'
import React from 'react'
import { shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import OrientationHOC from '../../src/components/OrientationHOC'

Enzyme.configure({ adapter: new Adapter() });

describe('OrientationHOC', () => {
let ElementToBeWrapped = 'TestElement'
let Component;
const orientation = 'PORTRAIT'

beforeEach(() => {
Component = OrientationHOC(ElementToBeWrapped)
})

it('is function', () => {
expect(OrientationHOC).toBeInstanceOf(Function)
})

it('renders correctly', () => {
const tree = renderer.create(<Component />).toJSON();
expect(tree).toMatchSnapshot();
})

it('initial state', () => {
const component = shallow(<Component />)
expect(component.state()).toEqual({ orientation });
})

it('handleLayoutChange should set state', () => {
const component = shallow(<Component />)
component.setState({ orientation: 'LANDSCAPE' })
component.instance().handleLayoutChange()
expect(component.state('orientation')).toEqual(orientation);
})
})
16 changes: 16 additions & 0 deletions __tests__/components/__snapshots__/OrientationHOC.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`OrientationHOC renders correctly 1`] = `
<View
onLayout={[Function]}
style={
Object {
"flex": 1,
}
}
>
<TestElement
orientation="PORTRAIT"
/>
</View>
`;
Loading

0 comments on commit ff57c5a

Please sign in to comment.