Skip to content

Instantly share code, notes, and snippets.

@sj82516
Created February 22, 2020 05:42
Show Gist options
  • Save sj82516/4181f3c41a70f95b9ea42c0573ce9dcc to your computer and use it in GitHub Desktop.
Save sj82516/4181f3c41a70f95b9ea42c0573ce9dcc to your computer and use it in GitHub Desktop.
const expect = require('chai').expect;
const sinon = require('sinon');
const UserManager = require('../../user/user.manager');
describe('userManger', () => {
let userManager = null;
let sandbox = sinon.createSandbox();
const findUserStub = sandbox.stub();
const fakeDB = {
collection: sinon.fake.returns({
findOne: findUserStub
})
}
before(() => {
userManager = new UserManager(fakeDB);
expect(fakeDB.collection.args[0][0]).to.be.equal('user');
expect(fakeDB.collection.calledOnce).to.be.equal(true);
})
afterEach(()=>{
sandbox.restore();
})
describe('findUser', () => {
it('find existed user', async () => {
const account = "test";
const password = "test";
const otherProp = "test";
findUserStub.returns({
account,
password,
otherProp
})
const user = await userManager.findUser({
account,
password
})
expect(user).to.deep.equal({
account,
password,
otherProp
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment