Skip to content

Instantly share code, notes, and snippets.

@jrcahoon
Last active June 21, 2018 20:55
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 jrcahoon/10ae2c684189f032002f23088a10a55f to your computer and use it in GitHub Desktop.
Save jrcahoon/10ae2c684189f032002f23088a10a55f to your computer and use it in GitHub Desktop.
[Jest Cookbook] Recipes for common tasks #jest #javascript #testing

Jest Cookbook

describe("MophiaGame", () => {
const find = foo.find;
it("should use a mocked find function", async () => {
Object.defineProperty(foo, "find", {
value: jest.fn(async () => {
return [{ name: "Jake", gangAffiliation: true }];
})
});
const mg = new MophiaGame();
const result = await mg.findMophia();
expect(result[0].name).toBe("Jake");
Object.defineProperty(foo, "find", { value: find });
});
it("should use the original find function", async () => {
const mg = new MophiaGame();
const result = await mg.findMophia();
expect(result[0].name).toBe("Jake");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment