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