Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import React, { useState } from "react";
  2. import { View, Button } from "react-native";
  3. import { shallow } from "enzyme";
  4.  
  5. const Example = function({ button2Press }) {
  6. const [name, setName] = useState("");
  7.  
  8. return (
  9. <View>
  10. <Button title="Button 1" onPress={() => setName("Hello")} />
  11. <Button title="Button 2" onPress={() => button2Press(name)} />
  12. </View>
  13. );
  14. };
  15.  
  16. describe("Example", () => {
  17. it("updates the state", () => {
  18. const button2Press = jest.fn();
  19. const wrapper = shallow(<Example button2Press={button2Press} />)
  20. const button1 = wrapper.findWhere(node => node.prop("title") === "Button 1")
  21. .first();
  22. const button2 = wrapper.findWhere(node => node.prop("title") === "Button 2")
  23. .first();
  24.  
  25. button1.props().onPress();
  26. button2.props().onPress();
  27.  
  28. expect(button2Press).toHaveBeenCalledWith("Hello");
  29. });
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement