Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Last active October 5, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DawnImpulse/59b734e6a15f4c95b293760a6d5a2f04 to your computer and use it in GitHub Desktop.
Save DawnImpulse/59b734e6a15f4c95b293760a6d5a2f04 to your computer and use it in GitHub Desktop.
ES6 + Babel + Sinon
// credits - https://github.com/sinonjs/sinon/issues/1358#issuecomment-288566305
// first install babel-plugin-rewire
// then add plugin to .babelrc as
// "plugins" : ["rewire"]
import token, {clientToken} from '../../../../app/util/token'
import * as esat from 'esat'
import * as proxyquire from 'proxyquire'
describe("token handling", () => {
describe("generating client token", () => {
before(() => {
token.__Rewire__('generate',sinon.stub().resolves({token: "", rtk: 0}))
});
it('should contains token key', () => {
return clientToken({uid:"abc"})
.should
.be
.fulfilled;
});
})
});
// credits - https://stackoverflow.com/a/46135220/4969957
import token from '../../../../app/util/token'
import * as esat from 'esat'
import * as proxyquire from 'proxyquire'
describe("token handling", () => {
describe("generating client token", () => {
const stub = {};
before(() => {
stub.generate = (opt, key) => {
return new Promise((resolve, reject) => {
resolve({token: "", rtk: 0})
});
};
});
it('should contains token key', () => {
const service = proxyquire.load('../../../../app/util/token', {esat: stub});
return service.clientToken({uid: "abc"})
.should
.eventually
.be
.a('string')
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment