Last active
June 17, 2020 12:20
-
-
Save brandonweis/f195ba645d46b957171cc868dbdf0122 to your computer and use it in GitHub Desktop.
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
| const caughtFunction = () => { | |
| try { | |
| blarg; | |
| } catch (e) { | |
| throw new Error('Ghaaa!'); | |
| } | |
| } | |
| const throwingFunction = () => { | |
| throw new Error('Ghaaa!'); | |
| } | |
| const badFunction = () => { | |
| blarg; | |
| } | |
| describe('toThrow', function() { | |
| beforeEach(() => { | |
| jest.spyOn(console, 'error') | |
| console.error.mockImplementation(() => {}) | |
| }) | |
| afterEach(() => { | |
| console.error.mockRestore() | |
| }) | |
| // When asserting .toThrow, the error is expected. | |
| // So this should not pollute the terminal output with a stacktrace: | |
| it('should not vomit to console', () => { | |
| // This is nicely silent: | |
| expect(() => { | |
| caughtFunction(); | |
| }).toThrow('Ghaaa!') | |
| // and this too: | |
| expect(() => { | |
| throwingFunction(); | |
| }).toThrow('Ghaaa!') | |
| // and even this...: | |
| expect(() => { | |
| badFunction(); | |
| }).toThrow() | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment