-
A @fbjest mistake that both I & a coworker have made in the past few weeks - Putting jest.mock() inside of a describe() block, then wondering why the original dependency was still called. (solution below 👇)
-
As @kentcdodds explains (github.com/kentcdodds/how-jest-mocking-works), it's because
jest.mock()
has to happen beforeimport
in order to replace it. Jest hoists it for you...but if it's inside adescribe
block, it only gets hoisted to the beginning ofdescribe
, which is not beforeimport
.