mercredi 26 septembre 2018

Testing an isolated function of a component in React Jest

I am fairly new to Jest and Enzyme and I stumbled a cross a problem:

I have a Component which renders Children and also calls a method of those children. I achieve that by using refs. I call these functions something like:

somefunction = () => {
   this.myReference.current.childFunction();
   this.doSomethingOther();
}    

I now want to test the function somefunction. I want to check if the doSomethingOther function was called. Using a shallow render I cannot achieve that. The test would succeed if this.myReference.current.childFunction(); wasn't called. Jest cannot know it because it only renders shallow and therefore throws an error.

I may be missing the full understanding. I wonder if someone has a Idea to test this function without using mount.

Regards

Bob

Aucun commentaire:

Enregistrer un commentaire