0
How can I test this function with Jest and Enzyme?
addProducts = id => {
toast.success("Product added", {
position: toast.POSITION.TOP_RIGHT
});
history.push(`/product/${id}`);
};
I was using this bit of code, but it wasn’t enough ...
it("Must return added addProduct with success message", () => {
const componente = shallow(<AddProduct />);
const spy = jest.spyOn(wrapper.instance(), "addProducts");
expect(spy).toBeTruthy();
});
Can you show more code? what is
wrapper
for example?– Sergio
Victor, it’s not an answer to your question, but it’s a suggestion: Use the React-testing-library. You may fall into an error testing implementation and not the code itself because of Enzyme. Anyway, to test there you need to check if Toast appeared on the screen. It seems to me that in your test code you are testing if addProducts appears and it is not actually rendered but Toast.
– Carlos Querioz