Last active
August 11, 2018 15:53
-
-
Save shierro/ce4a85d0fc3fc5a393f1cbde6ed9bfc2 to your computer and use it in GitHub Desktop.
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
import UserConnector from './user' | |
import sinon from 'sinon' | |
import mongoose from 'mongoose' | |
import UserModel from '../../models/user' | |
describe("User connector", () => { | |
it("should register user", async () => { | |
const expectedUser = { | |
firstName: "adsfja", | |
lastName: "adsfja", | |
email: "[email protected]", | |
password: "password123" | |
} | |
var myStub = sinon | |
.stub(UserModel.prototype, 'save') | |
.callsFake(() => Promise.resolve(expectedUser)) | |
const userConnector = new UserConnector(); | |
// since register is used as async, we should expect it to return a promise | |
const user = await userConnector.register(expectedUser) | |
expect(user).toEqual({ | |
firstName: "adsfja", | |
lastName: "adsfja", | |
email: "[email protected]" | |
}) | |
myStub.restore() // don't forget to restore stubbed function | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment