-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add stack traces to test message for test error. (#545)
- For thrown error scenarios provides the location of the error thrown inside the tested code with fully navigable trace. - For non throw error scenarios provides additional context on the failed assertion. Co-authored-by: ArthurHub <[email protected]>
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
|
||
export function add(a: number, b: number) { | ||
return a + b | ||
} | ||
|
||
export function sum(from: number, to: number) { | ||
return (from + to) * (to - from + 1) / 2 | ||
} | ||
|
||
export function addError(from: number, to: number) { | ||
doSomething() | ||
return add(from, to) | ||
} | ||
|
||
function doSomething() { | ||
throw new Error('Something went wrong'); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { addError } from '../src/add'; | ||
|
||
describe('throw error', () => { | ||
it('passes expecting an error to be thrown', () => { | ||
expect(()=>addError(1, 1)).toThrow() | ||
}) | ||
|
||
it('fails with error thrown', () => { | ||
expect(addError(1, 1)).toBe(2) | ||
}) | ||
}) |
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