Last active
September 6, 2023 12:46
-
-
Save thisismydesign/bc6b198e273d629647658f9721bf7cf7 to your computer and use it in GitHub Desktop.
Mocking per test case with Jest /1
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
jest.mock("MyOtherComponent", () => { | |
return require | |
.requireActual("TestUtils") | |
.mockOriginalFunctionality("MyOtherComponent"); | |
}); | |
describe("<Component />", () => { | |
it("works", () => { | |
// MyOtherComponent works as usual | |
}): | |
describe("when something silly happens", () => { | |
beforeEach(() => { | |
MyOtherComponent.someFunction.mockImplementationOnce(() => { | |
throw new Error("oops"); | |
}); | |
}); | |
it("displays error", () => { | |
// MyOtherComponent.someFunction throws | |
}): | |
}); | |
it("still works", () => { | |
// MyOtherComponent works as usual again | |
}): | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment