Skip to content

Commit

Permalink
Add more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nysamnang committed Feb 27, 2019
1 parent 250a51e commit 2a9446d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 37 deletions.
97 changes: 63 additions & 34 deletions __tests__/RBSheet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,71 @@ import RBSheet from "../src";
Enzyme.configure({ adapter: new Adapter() });

describe("React Native Raw Bottom Sheet", () => {
it("should render correctly with no props", () => {
const component = shallow(<RBSheet />);
expect(component).toMatchSnapshot();
});
describe("Render", () => {
it("should render correctly with no props", () => {
const wrapper = shallow(<RBSheet />);
expect(wrapper).toMatchSnapshot();
});

it("should render correctly with given props", () => {
const wrapper = shallow(
<RBSheet
height={300}
minClosingHeight={100}
duration={350}
closeOnSwipeDown={false}
closeOnPressMask={false}
customStyles={{
wrapper: {
backgroundColor: "#00000066"
},
container: {
justifyContent: "center",
alignItems: "center"
}
}}
onClose={() => {}}
/>
);
expect(wrapper).toMatchSnapshot();
});

it("should render correctly with given props", () => {
const component = shallow(
<RBSheet
height={300}
minClosingHeight={100}
duration={350}
closeOnSwipeDown={false}
closeOnPressMask={false}
customStyles={{
wrapper: {
backgroundColor: "#00000066"
},
container: {
justifyContent: "center",
alignItems: "center"
}
}}
onClose={() => {}}
/>
);
expect(component).toMatchSnapshot();
it("should render correctly with any children", () => {
const wrapper = shallow(
<RBSheet>
<View>
<Text>React Native Raw Bottom Sheet</Text>
</View>
</RBSheet>
);
expect(wrapper).toMatchSnapshot();
});
});

it("should render correctly with any children", () => {
const component = shallow(
<RBSheet>
<View>
<Text>React Native Raw Bottom Sheet</Text>
</View>
</RBSheet>
);
expect(component).toMatchSnapshot();
describe("Method", () => {
it("should createPanResponder called", () => {
const wrapper = shallow(<RBSheet />);
const createPanResponder = jest.spyOn(RBSheet.prototype, "createPanResponder");
wrapper.instance().createPanResponder({ closeOnSwipeDown: true, height: 300 });
expect(createPanResponder).toHaveBeenCalled();
});

it("should component open", () => {
jest.useFakeTimers(); // https://github.com/facebook/jest/issues/4359
const wrapper = shallow(<RBSheet />);
const setModalVisible = jest.spyOn(RBSheet.prototype, "setModalVisible");
wrapper.instance().open();
expect(setModalVisible).toHaveBeenCalled();
expect(wrapper.state().modalVisible).toBe(true);
});

it("should component close", () => {
jest.useFakeTimers(); // https://github.com/facebook/jest/issues/4359
const wrapper = shallow(<RBSheet />);
const setModalVisible = jest.spyOn(RBSheet.prototype, "setModalVisible");
wrapper.instance().close();
expect(setModalVisible).toHaveBeenCalled();
expect(wrapper.state().modalVisible).toBe(false);
});
});
});
6 changes: 3 additions & 3 deletions __tests__/__snapshots__/RBSheet.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`React Native Raw Bottom Sheet should render correctly with any children 1`] = `ShallowWrapper {}`;
exports[`React Native Raw Bottom Sheet Render should render correctly with any children 1`] = `ShallowWrapper {}`;

exports[`React Native Raw Bottom Sheet should render correctly with given props 1`] = `ShallowWrapper {}`;
exports[`React Native Raw Bottom Sheet Render should render correctly with given props 1`] = `ShallowWrapper {}`;

exports[`React Native Raw Bottom Sheet should render correctly with no props 1`] = `ShallowWrapper {}`;
exports[`React Native Raw Bottom Sheet Render should render correctly with no props 1`] = `ShallowWrapper {}`;

0 comments on commit 2a9446d

Please sign in to comment.