Skip to content

Commit 58b9f4f

Browse files
authored
Merge pull request #680 from fable-hub/add_optional_msg_in_expect
feat: add support for optional message in `expect` API
2 parents bab108b + f0b2e13 commit 58b9f4f

6 files changed

Lines changed: 23 additions & 3 deletions

File tree

build.sh

100644100755
File mode changed.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "feliz-packages",
23
"private": true,
34
"scripts": {
45
"publish-docs": "npm run build && node publish.js",

src/Vitest/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 1.0.0-rc.2 - 2025-10-20
11+
12+
### Changed
13+
14+
- PR #680: Add support for optional message in expect API (by @MangelMaxime)
15+
1016
## 1.0.0-rc.1 - 2025-09-18
1117

1218
### Added

src/Vitest/Library.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ type TestAPI =
239239
type TestContext =
240240
abstract member task: Task
241241
abstract member expect: value: obj -> IAssertion<obj>
242+
abstract member expect: value: obj * ?msg: string -> IAssertion<obj>
242243
abstract member skip: unit -> unit
243244
abstract member skip: note: string -> unit
244245
abstract member skip: condition: bool -> unit
@@ -396,7 +397,7 @@ type Vitest =
396397
// static member expectPromise<'a>(value: Promise<'a>) : IPromiseAssertion<'a> = jsNative
397398

398399
[<ImportMember("vitest")>]
399-
static member expect<'a>(value: 'a) : IAssertion<'a> = jsNative
400+
static member expect<'a>(value: 'a, ?msg : string) : IAssertion<'a> = jsNative
400401

401402
[<Import("expect", "vitest")>]
402403
static member Expect: ExpectStatic = jsNative

tests/Vitest/Program.test.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Vitest.describe("Vitest basics", fun () ->
2828
Vitest.expect(result).toBe(5)
2929
)
3030

31+
Vitest.test("sum adds two numbers with custom message", fun () ->
32+
let result = Examples.sum 2 3
33+
// To test this API, you need to make the test fail and check the message in the output
34+
Vitest.expect(result, "custom message, value should be 5").toBe(5)
35+
)
36+
3137
Vitest.test("TestOptions timeout", TestOptions(timeout = 1000), fun () ->
3238
let result = Examples.sum 2 3
3339
Vitest.expect(result).toBe(5)
@@ -198,6 +204,12 @@ Vitest.describe("TextContext", fun () ->
198204
ctx.expect(result).toBe(5)
199205
)
200206

207+
Vitest.test("sum adds two numbers with context and custom message", fun (ctx: TestContext) ->
208+
let result = Examples.sum 2 3
209+
// To test this API, you need to make the test fail and check the message in the output
210+
ctx.expect(result, "custom message, value should be 5").toBe(5)
211+
)
212+
201213
Vitest.test("sum adds two numbers with context", fun (ctx: TestContext) ->
202214
ctx.skip()
203215
failwith "This test should be skipped"

0 commit comments

Comments
 (0)