Last active
October 5, 2018 16:02
-
-
Save DawnImpulse/59b734e6a15f4c95b293760a6d5a2f04 to your computer and use it in GitHub Desktop.
ES6 + Babel + Sinon
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
// 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; | |
}); | |
}) | |
}); |
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
// 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