Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created March 29, 2018 21:56
Show Gist options
  • Save theKashey/b110a46d805db1ce0483a875a1607fc9 to your computer and use it in GitHub Desktop.
Save theKashey/b110a46d805db1ce0483a875a1607fc9 to your computer and use it in GitHub Desktop.
advanced rewriremock
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