Created
August 10, 2017 17:03
-
-
Save thomasmichaelwallace/a0d876a2b52655cb2e059dc08a90b41d to your computer and use it in GitHub Desktop.
A quick introduction to inject-loader.
This file contains hidden or 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
/* eslint-env mocha */ | |
/* eslint-disable no-unused-expressions */ | |
import { expect, use } from 'chai'; // eslint-disable-line import/no-named-default | |
import sinon from 'sinon'; | |
import sinonChai from 'sinon-chai'; | |
/* directory structure: | |
/tests/post.spec.js // this test. | |
/src/post.js // the module to test. | |
/adapters/mailer/js // a mail-out adapter. | |
*/ | |
import injectPost from 'inject-loader!../src/post'; // eslint-disable-line | |
use(sinonChai); | |
describe('A postman', () => { | |
it('should deliver mail.' () => { | |
// test mailer.js adapter: | |
let sendMail = sinon.spy(Promise.resolve); | |
const testMailer = { sendMail }; | |
// import { post } from '../src/posts' with ../adapters/mailer.js replaced with testMailer. | |
const post = injectPost({ '../adapters/mailer': testMailer }).post; | |
// actual test: | |
return post({ vaugeAddress: 'Red house' }) | |
.then(() => expect(sendMail).to.be.calledWith({ address: '123 Postman Lane' })); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment