cometkim / rescript-vitest

ReScript bindings to Vitest
MIT License
42 stars 9 forks source link

List assertions bug / custom expect.extend for ReScript native types #19

Closed illusionalsagacity closed 2 months ago

illusionalsagacity commented 2 months ago

When writing tests in this branch

I get the following result for this code:

test(
  "toContain",
  _t => {
    let value = list{1, 2, 3}
    expect(value)->Expect.List.toContain(1)
    expect(value)->Expect.List.toContain(2)
    expect(value)->Expect.List.toContain(3)
    expect(value)->Expect.not->Expect.List.toContain(4)
  },
)
FAIL  tests/assertions.test.mjs > Expect > List > toContain
Error: Invalid Chai property: tl. Did you mean "to"?
 ❯ length node_modules/rescript/lib/es6/belt_List.js:622:12
 ❯ Module.toArray node_modules/rescript/lib/es6/belt_List.js:660:13
 ❯ toContain src/Vitest.mjs:761:20
    759|
    760| function toContain(expected, item) {
    761|   return Belt_List.toArray(expected).toContain(item);
       |                    ^
    762| }
    763|
 ❯ Module._2 node_modules/rescript/lib/es6/curry.js:81:12
 ❯ tests/assertions.test.mjs:427:31
 ❯ Module._1 node_modules/rescript/lib/es6/curry.js:32:12
 ❯ src/Vitest.mjs:144:17
 ❯ Module._1 node_modules/rescript/lib/es6/curry.js:32:12
 ❯ src/Vitest.mjs:102:24

I think a good way to solve this would be to extend expect and write the matchers in ReScript code, then have consumers of the library install that in their test setup. It would also allow better support for ReScript-native types like List, Option, and Result, like customizing the error messages you see.

cometkim commented 2 months ago

Thanks for reporting! Will be fixed in next release