Skip to content

Instantly share code, notes, and snippets.

@shlomokraus
Last active January 20, 2019 20:23
Show Gist options
  • Save shlomokraus/47ab5330256013210d291ecafa697a85 to your computer and use it in GitHub Desktop.
Save shlomokraus/47ab5330256013210d291ecafa697a85 to your computer and use it in GitHub Desktop.
Example of UserService test - without mockshot
import { UserService } from "../src/UserService";
describe("UserService", () => {
// fake database service
const db = {
findOneById: async (id) => {
const name = "Some Name";
const email = "[email protected]";
return {
id,
name,
email
}
}
}
it("Should get user", async () => {
// prepare
const userService = new UserService(db);
const id = "abc";
// execute
const user = await userService.getUser(id);
// assert
expect(user.id).toEqual(id)
expect(user.name).toBeDefined()
expect(user.email).toBeDefined()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment