-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for actual and expected values in errors (via #1215)
- Loading branch information
Showing
4 changed files
with
130 additions
and
3 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
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
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
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,74 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { runVitestInlineTest } from "../utils.js"; | ||
|
||
describe("expect", () => { | ||
it("should add actual and expected values when using expect", async () => { | ||
const { tests } = await runVitestInlineTest(` | ||
import { test, expect } from "vitest"; | ||
test("fail test", () => { | ||
expect("a value").toEqual("the other one"); | ||
}); | ||
`); | ||
|
||
expect(tests).toHaveLength(1); | ||
expect(tests).toMatchObject([ | ||
{ | ||
name: "fail test", | ||
status: "failed", | ||
statusDetails: { | ||
message: "expected 'a value' to deeply equal 'the other one'", | ||
expected: "the other one", | ||
actual: "a value", | ||
}, | ||
}, | ||
]); | ||
}); | ||
it("should add actual and expected values when using expect with match object", async () => { | ||
const { tests } = await runVitestInlineTest(` | ||
import { test, expect } from "vitest"; | ||
test("fail test", () => { | ||
expect({ nested: { obj: "value", n: 123}}).toMatchObject({ nested: { obj: "some"} }); | ||
}); | ||
`); | ||
|
||
expect(tests).toHaveLength(1); | ||
expect(tests).toMatchObject([ | ||
{ | ||
name: "fail test", | ||
status: "failed", | ||
statusDetails: { | ||
expected: "Object {\n" + ' "nested": Object {\n' + ' "obj": "some",\n' + " },\n" + "}", | ||
actual: "Object {\n" + ' "nested": Object {\n' + ' "obj": "value",\n' + " },\n" + "}", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
// this is the way vitest process errors | ||
it("should add actual and expected values when regular exception is thrown", async () => { | ||
const { tests } = await runVitestInlineTest(` | ||
import { test, expect } from "vitest"; | ||
test("fail test", () => { | ||
throw new Error("fail!") | ||
}); | ||
`); | ||
|
||
expect(tests).toHaveLength(1); | ||
expect(tests).toMatchObject([ | ||
{ | ||
name: "fail test", | ||
status: "broken", | ||
statusDetails: { | ||
expected: "undefined", | ||
actual: "undefined", | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); |