pepopowitz’s avatarpepopowitz’s Twitter Archive—№ 1,231

    1. 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 👇)
  1. …in reply to @pepopowitz
    As @kentcdodds explains (github.com/kentcdodds/how-jest-mocking-works), it's because jest.mock() has to happen before import in order to replace it. Jest hoists it for you...but if it's inside a describe block, it only gets hoisted to the beginning of describe, which is not before import.