Skip to content

Instantly share code, notes, and snippets.

@shierro
Last active August 11, 2018 15:53
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 shierro/ce4a85d0fc3fc5a393f1cbde6ed9bfc2 to your computer and use it in GitHub Desktop.
Save shierro/ce4a85d0fc3fc5a393f1cbde6ed9bfc2 to your computer and use it in GitHub Desktop.
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: "adsfja@alsda.com",
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: "adsfja@alsda.com"
})
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