Jest test example from Chapter 15 does not work
90sidort opened this issue · 2 comments
Hi, unfortunately unit test example from chapter 15 (section Adding the test) does not work. This is the error:
TypeError: Cannot read property 'mockReturnValue' of undefined
-
How is importing auth from auth-helper expected to work if mocked authorization object is also defined as const auth:
import auth from './../auth/auth-helper.js'
andconst auth = dummyAuthObject
. Doesnt this make two variables called auth? -
Why isnt onRemove function passed as a prop when it is required in Post component?
Hey @90sidort,
- You are right. The line
const auth = dummyAuthObject
does contain an error, the variable should be renamed or this line can be omitted anddummyAuthObject
used directly in the example test. - The
onRemove
prop can be added and passed an empty function, but it's presence or lack thereof doesn't affect the specific test case. Though adding the prop would be wiser to at least clean up the test console. - There seems to be one more issue not indicated in the book about testing the Post component without the Comments section. For the version of Material-UI used in the book examples, the Textarea does not play well with react-test-renderer, so for this test code example to run you would have to comment out the Comments component present in the Post component.
You can find the working example that takes all of these into consideration, here: shamahoque/mern-social@335ed8b
Thank you for taking the time and going through the example code, and pointing out these issues! This will help us add an errata for other readers.
Thank you @shamahoque for quick and detailed response. Now it works perfectly.