Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from "react";
- import { View, Button } from "react-native";
- import { shallow } from "enzyme";
- const Example = function({ button2Press }) {
- const [name, setName] = useState("");
- return (
- <View>
- <Button title="Button 1" onPress={() => setName("Hello")} />
- <Button title="Button 2" onPress={() => button2Press(name)} />
- </View>
- );
- };
- describe("Example", () => {
- it("updates the state", () => {
- const button2Press = jest.fn();
- const wrapper = shallow(<Example button2Press={button2Press} />)
- const button1 = wrapper.findWhere(node => node.prop("title") === "Button 1")
- .first();
- const button2 = wrapper.findWhere(node => node.prop("title") === "Button 2")
- .first();
- button1.props().onPress();
- button2.props().onPress();
- expect(button2Press).toHaveBeenCalledWith("Hello");
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement