Created
March 29, 2018 21:56
-
-
Save theKashey/b110a46d805db1ce0483a875a1607fc9 to your computer and use it in GitHub Desktop.
advanced rewriremock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rewiremock from 'rewiremock'; | |
import sinon from 'sinon'; | |
const Launch = sinon.stub() | |
// "require" module name | |
rewiremock(() => require('./rocket-silo')).with({ | |
Launch: sinon.stub() | |
}); | |
// "import" module name. And let system to lead rewiremock to the real file | |
rewiremock(() => import('doom-scheduler')).with({ | |
theDay: Promise.resolve() | |
}); | |
// rewiremock async API. | |
await rewiremock.module('./dooms-day.js'); | |
expect(Launch).toHaveBeenCalled(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment