score:3

enzyme shallow specifically is meant to not be able to test children of the component being passed. because staticrouter is the parent component, componentform is never getting properly rendered, and so link will never be in the view. so, using shallow you can test that staticrouter properly renders a componentform, but you cannot look inside componentform.

you have two options:

first, you could just pass componentform to the shallow method. you mentioned in comments that this caused things to break. that's likely because componentform expects props from staticrouter. you can pass these manually:

shallow(<componentform routerprop1={'foo'} routerprop2={'bar'} />);

your other option is to to a deep render using enzyme render. simply replace shallow with render and that should work. do note that this is discouraged for several reasons. first, as noted with shallow, by not doing a shallow render, you possibly allow yourself to test things which the component you are passing in has no knowledge of. for example, staticrouter has no knowledge about componentform's link, and so the test for componentform's link should be independent of staticrouter. second, render is much slower than shallow, so if you have lots of tests and lots of components, you will notice a considerable slowdown.


Related Query

More Query from same tag