Last active
January 20, 2019 20:23
-
-
Save shlomokraus/47ab5330256013210d291ecafa697a85 to your computer and use it in GitHub Desktop.
Example of UserService test - without mockshot
This file contains hidden or 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 { 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, | |
} | |
} | |
} | |
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