From adfddaab3b1ebe216dfbe059c41732ff58d1e26d Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 21 Jan 2025 21:26:33 -0500 Subject: [PATCH] feat: bind additional Assert functions - notEqual - notDeepEqual - strictEqual - notStrictEqual - deepStrictEqual - fail --- src/Vitest_Assert.res | 39 ++++ tests/assertions.test.res | 440 +++++++++++++++++++++----------------- 2 files changed, 288 insertions(+), 191 deletions(-) diff --git a/src/Vitest_Assert.res b/src/Vitest_Assert.res index 2be3285..eea3494 100644 --- a/src/Vitest_Assert.res +++ b/src/Vitest_Assert.res @@ -14,7 +14,46 @@ external unreachable: (~message: string=?, unit) => unit = "unreachable" @inline let equal = (~message=?, a, b) => assert_obj->equal(a, b, message->Js.Undefined.fromOption) +@send external notEqual: (t, 'a, 'a, Js.undefined) => unit = "notEqual" + +@inline +let notEqual = (~message=?, a, b) => assert_obj->notEqual(a, b, message->Js.Undefined.fromOption) + @send external deepEqual: (t, 'a, 'a, Js.undefined) => unit = "deepEqual" @inline let deepEqual = (~message=?, a, b) => assert_obj->deepEqual(a, b, message->Js.Undefined.fromOption) + +@send external notDeepEqual: (t, 'a, 'a, Js.undefined) => unit = "notDeepEqual" + +@inline +let notDeepEqual = (~message=?, a, b) => + assert_obj->notDeepEqual(a, b, message->Js.Undefined.fromOption) + +@send external strictEqual: (t, 'a, 'a, Js.undefined) => unit = "strictEqual" + +@inline +let strictEqual = (~message=?, a, b) => + assert_obj->strictEqual(a, b, message->Js.Undefined.fromOption) + +@send external notStrictEqual: (t, 'a, 'a, Js.undefined) => unit = "notStrictEqual" + +@inline +let notStrictEqual = (~message=?, a, b) => + assert_obj->notStrictEqual(a, b, message->Js.Undefined.fromOption) + +@send external deepStrictEqual: (t, 'a, 'a, Js.undefined) => unit = "deepStrictEqual" + +@inline +let deepStrictEqual = (~message=?, a, b) => + assert_obj->deepStrictEqual(a, b, message->Js.Undefined.fromOption) + +@send external fail: (t, Js.undefined<'a>, Js.undefined<'a>, Js.undefined) => unit = "fail" + +@inline +let fail = (~actual=?, ~expected=?, ~message=?) => + assert_obj->fail( + actual->Js.Undefined.fromOption, + expected->Js.Undefined.fromOption, + message->Js.Undefined.fromOption, + ) diff --git a/tests/assertions.test.res b/tests/assertions.test.res index 7bd885e..0edd11b 100644 --- a/tests/assertions.test.res +++ b/tests/assertions.test.res @@ -1,5 +1,4 @@ open Vitest -open! Bindings.BuiltIn describe("Assert", () => { test("assert_", _t => { @@ -9,7 +8,7 @@ describe("Assert", () => { Assert.assert_(1 == 1) }) - test("unreachable", _t => { + test("unreachable", t => { try { let _ = Js.Exn.raiseError("error") Assert.unreachable() @@ -18,133 +17,190 @@ describe("Assert", () => { } try { - expect(true)->Expect.toBe(true) + t->expect(true)->Expect.toBe(true) } catch { - | _ => Assert.unreachable() + | _ => Assert.unreachable() + } + }) + + test("equal", _ctx => { + Assert.equal(1, 1) + Assert.equal(2., 2.) + Assert.equal("one", "one") + Assert.equal(true, true) + }) + + test("notEqual", _ctx => { + Assert.notEqual(1, 2) + Assert.notEqual(2., 3.) + Assert.notEqual("one", "two") + Assert.notEqual(true, false) + }) + + test("deepEqual", _ctx => { + Assert.deepEqual({"foo": "bar"}, {"foo": "bar"}) + Assert.deepEqual([1, 2, 3], [1, 2, 3]) + Assert.deepEqual(Some(1), Some(1)) + Assert.deepEqual(None, None) + }) + + test("notDeepEqual", _ctx => { + Assert.notDeepEqual({"foo": "bar"}, {"foo": "baz"}) + Assert.notDeepEqual([1, 2, 3], [4, 5, 6]) + Assert.notDeepEqual(Some(1), Some(2)) + Assert.notDeepEqual(Some(1), None) + }) + + test("strictEqual", _ctx => { + Assert.strictEqual(1, 1) + Assert.strictEqual(2., 2.) + Assert.strictEqual("one", "one") + Assert.strictEqual(true, true) + }) + + test("notStrictEqual", _ctx => { + Assert.notStrictEqual(1, 2) + Assert.notStrictEqual(2., 3.) + Assert.notStrictEqual("one", "two") + Assert.notStrictEqual(true, false) + }) + + test("deepStrictEqual", _ctx => { + Assert.deepStrictEqual({"foo": "bar"}, {"foo": "bar"}) + Assert.deepStrictEqual([1, 2, 3], [1, 2, 3]) + Assert.deepStrictEqual(Some(1), Some(1)) + Assert.deepStrictEqual(None, None) + }) + + test("fail", _ctx => { + try { + Assert.fail(~message="This test should fail") + } catch { + | _ => Assert.assert_(~message="threw error", true) } }) }) describe("Expect", () => { - test("toBe", _t => { - expect(1)->Expect.toBe(1) - expect(2.)->Expect.toBe(2.) - expect("one")->Expect.toBe("one") - expect(true)->Expect.toBe(true) + test("toBe", t => { + t->expect(1)->Expect.toBe(1) + t->expect(2.)->Expect.toBe(2.) + t->expect("one")->Expect.toBe("one") + t->expect(true)->Expect.toBe(true) }) - test("not", _t => { - expect(1)->Expect.not->Expect.toBe(2) - expect(2.)->Expect.not->Expect.toBe(1.) - expect("one")->Expect.not->Expect.toBe("two") - expect(true)->Expect.not->Expect.toBe(false) + test("not", t => { + t->expect(1)->Expect.not->Expect.toBe(2) + t->expect(2.)->Expect.not->Expect.toBe(1.) + t->expect("one")->Expect.not->Expect.toBe("two") + t->expect(true)->Expect.not->Expect.toBe(false) }) - test("eq", _t => { - expect(1)->Expect.eq(1) - expect(2.)->Expect.eq(2.) - expect("one")->Expect.eq("one") - expect(true)->Expect.eq(true) + test("eq", t => { + t->expect(1)->Expect.eq(1) + t->expect(2.)->Expect.eq(2.) + t->expect("one")->Expect.eq("one") + t->expect(true)->Expect.eq(true) }) - test("toBeDefined", _t => { - Js.Undefined.return(1)->expect->Expect.toBeDefined - Js.Undefined.return(2.)->expect->Expect.toBeDefined - Js.Undefined.return("one")->expect->Expect.toBeDefined - Js.Undefined.return(true)->expect->Expect.toBeDefined + test("toBeDefined", t => { + t->expect(Js.Undefined.return(1))->Expect.toBeDefined + t->expect(Js.Undefined.return(2.))->Expect.toBeDefined + t->expect(Js.Undefined.return("one"))->Expect.toBeDefined + t->expect(Js.Undefined.return(true))->Expect.toBeDefined }) - test("toBeUndefined", _t => { - Js.Undefined.empty->expect->Expect.toBeUndefined + test("toBeUndefined", t => { + t->expect(Js.Undefined.empty)->Expect.toBeUndefined }) - test("toBeTruthy", _t => { - expect({"foo": "bar"})->Expect.toBeTruthy - expect(1)->Expect.toBeTruthy - expect(0)->Expect.not->Expect.toBeTruthy - expect("one")->Expect.toBeTruthy - expect("")->Expect.not->Expect.toBeTruthy - expect(true)->Expect.toBeTruthy - expect(false)->Expect.not->Expect.toBeTruthy + test("toBeTruthy", t => { + t->expect({"foo": "bar"})->Expect.toBeTruthy + t->expect(1)->Expect.toBeTruthy + t->expect(0)->Expect.not->Expect.toBeTruthy + t->expect("one")->Expect.toBeTruthy + t->expect("")->Expect.not->Expect.toBeTruthy + t->expect(true)->Expect.toBeTruthy + t->expect(false)->Expect.not->Expect.toBeTruthy }) - test("toBeFalsy", _t => { - expect(0)->Expect.toBeFalsy - expect(1)->Expect.not->Expect.toBeFalsy - expect("")->Expect.toBeFalsy - expect("one")->Expect.not->Expect.toBeFalsy - expect(false)->Expect.toBeFalsy - expect(true)->Expect.not->Expect.toBeFalsy + test("toBeFalsy", t => { + t->expect(0)->Expect.toBeFalsy + t->expect(1)->Expect.not->Expect.toBeFalsy + t->expect("")->Expect.toBeFalsy + t->expect("one")->Expect.not->Expect.toBeFalsy + t->expect(false)->Expect.toBeFalsy + t->expect(true)->Expect.not->Expect.toBeFalsy }) - test("toBeNull", _t => { - Js.Null.empty->expect->Expect.toBeNull + test("toBeNull", t => { + t->expect(Js.Null.empty)->Expect.toBeNull }) - test("toEqual", _t => { - expect(Ok(1))->Expect.toEqual(Ok(1)) - expect(Error("error"))->Expect.toEqual(Error("error")) - expect(Some("option"))->Expect.toEqual(Some("option")) - expect(None)->Expect.toEqual(None) - expect({"foo": "bar"})->Expect.toEqual({"foo": "bar"}) - expect(1)->Expect.toEqual(1) - expect(2.)->Expect.toEqual(2.) - expect("one")->Expect.toEqual("one") - expect(true)->Expect.toEqual(true) + test("toEqual", t => { + t->expect(Ok(1))->Expect.toEqual(Ok(1)) + t->expect(Error("error"))->Expect.toEqual(Error("error")) + t->expect(Some("option"))->Expect.toEqual(Some("option")) + t->expect(None)->Expect.toEqual(None) + t->expect({"foo": "bar"})->Expect.toEqual({"foo": "bar"}) + t->expect(1)->Expect.toEqual(1) + t->expect(2.)->Expect.toEqual(2.) + t->expect("one")->Expect.toEqual("one") + t->expect(true)->Expect.toEqual(true) }) - test("toBeSome", _t => { - Some(1)->expect->Expect.toBeSome - Some(2.)->expect->Expect.toBeSome - Some("one")->expect->Expect.toBeSome - Some(true)->expect->Expect.toBeSome - Some({"foo": "bar"})->expect->Expect.toBeSome + test("toBeSome", t => { + t->expect(Some(1))->Expect.toBeSome + t->expect(Some(2.))->Expect.toBeSome + t->expect(Some("one"))->Expect.toBeSome + t->expect(Some(true))->Expect.toBeSome + t->expect(Some({"foo": "bar"}))->Expect.toBeSome }) - test("toBeNone", _t => { - None->expect->Expect.toBeNone + test("toBeNone", t => { + t->expect(None)->Expect.toBeNone }) - test("toStrictEqual", _t => { - expect(Ok(1))->Expect.toStrictEqual(Ok(1)) - expect(Error("error"))->Expect.toStrictEqual(Error("error")) - expect(Some("option"))->Expect.toStrictEqual(Some("option")) - expect(None)->Expect.toStrictEqual(None) - expect({"foo": "bar"})->Expect.toStrictEqual({"foo": "bar"}) - expect(1)->Expect.toStrictEqual(1) - expect(2.)->Expect.toStrictEqual(2.) - expect("one")->Expect.toStrictEqual("one") - expect(true)->Expect.toStrictEqual(true) + test("toStrictEqual", t => { + t->expect(Ok(1))->Expect.toStrictEqual(Ok(1)) + t->expect(Error("error"))->Expect.toStrictEqual(Error("error")) + t->expect(Some("option"))->Expect.toStrictEqual(Some("option")) + t->expect(None)->Expect.toStrictEqual(None) + t->expect({"foo": "bar"})->Expect.toStrictEqual({"foo": "bar"}) + t->expect(1)->Expect.toStrictEqual(1) + t->expect(2.)->Expect.toStrictEqual(2.) + t->expect("one")->Expect.toStrictEqual("one") + t->expect(true)->Expect.toStrictEqual(true) }) - test("toContain", _t => { - expect([1, 2, 3])->Expect.toContain(1) - expect([1, 2, 3])->Expect.toContain(2) - expect([1, 2, 3])->Expect.toContain(3) - expect([1, 2, 3])->Expect.not->Expect.toContain(4) + test("toContain", t => { + t->expect([1, 2, 3])->Expect.toContain(1) + t->expect([1, 2, 3])->Expect.toContain(2) + t->expect([1, 2, 3])->Expect.toContain(3) + t->expect([1, 2, 3])->Expect.not->Expect.toContain(4) }) - test("toContainEqual", _t => { - expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 1}) - expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 2}) - expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 3}) - expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.not->Expect.toContainEqual({"foo": 4}) + test("toContainEqual", t => { + t->expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 1}) + t->expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 2}) + t->expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.toContainEqual({"foo": 3}) + t->expect([{"foo": 1}, {"foo": 2}, {"foo": 3}])->Expect.not->Expect.toContainEqual({"foo": 4}) }) - test("toMatchSnapshot", _t => { - expect(1)->Expect.toMatchSnapshot - expect(2.)->Expect.toMatchSnapshot - expect("one")->Expect.toMatchSnapshot - expect(true)->Expect.toMatchSnapshot - expect({"foo": "bar"})->Expect.toMatchSnapshot + test("toMatchSnapshot", t => { + t->expect(1)->Expect.toMatchSnapshot + t->expect(2.)->Expect.toMatchSnapshot + t->expect("one")->Expect.toMatchSnapshot + t->expect(true)->Expect.toMatchSnapshot + t->expect({"foo": "bar"})->Expect.toMatchSnapshot }) - test("toThrow", _t => { - expect(() => raise(Js.Exn.raiseError("error")))->Expect.toThrow + test("toThrow", t => { + t->expect(() => raise(Js.Exn.raiseError("error")))->Expect.toThrow }) - test("toThrowError", _t => { - expect(() => raise(Js.Exn.raiseError("error")))->Expect.toThrowError(~message="error") + test("toThrowError", t => { + t->expect(() => raise(Js.Exn.raiseError("error")))->Expect.toThrowError(~message="error") }) describe("Int", () => { @@ -153,37 +209,37 @@ describe("Expect", () => { () => { test( "toBeGreaterThan", - _t => { - expect(5)->Expect.Int.toBeGreaterThan(3) - expect(10)->Expect.Int.toBeGreaterThan(5) - expect(0)->Expect.Int.toBeGreaterThan(-5) + t => { + t->expect(5)->Expect.Int.toBeGreaterThan(3) + t->expect(10)->Expect.Int.toBeGreaterThan(5) + t->expect(0)->Expect.Int.toBeGreaterThan(-5) }, ) test( "toBeGreaterThanOrEqual", - _t => { - expect(5)->Expect.Int.toBeGreaterThanOrEqual(3) - expect(5)->Expect.Int.toBeGreaterThanOrEqual(5) - expect(10)->Expect.Int.toBeGreaterThanOrEqual(5) + t => { + t->expect(5)->Expect.Int.toBeGreaterThanOrEqual(3) + t->expect(5)->Expect.Int.toBeGreaterThanOrEqual(5) + t->expect(10)->Expect.Int.toBeGreaterThanOrEqual(5) }, ) test( "toBeLessThan", - _t => { - expect(3)->Expect.Int.toBeLessThan(5) - expect(5)->Expect.Int.toBeLessThan(10) - expect(-5)->Expect.Int.toBeLessThan(0) + t => { + t->expect(3)->Expect.Int.toBeLessThan(5) + t->expect(5)->Expect.Int.toBeLessThan(10) + t->expect(-5)->Expect.Int.toBeLessThan(0) }, ) test( "toBeLessThanOrEqual", - _t => { - expect(3)->Expect.Int.toBeLessThanOrEqual(5) - expect(5)->Expect.Int.toBeLessThanOrEqual(5) - expect(5)->Expect.Int.toBeLessThanOrEqual(10) + t => { + t->expect(3)->Expect.Int.toBeLessThanOrEqual(5) + t->expect(5)->Expect.Int.toBeLessThanOrEqual(5) + t->expect(5)->Expect.Int.toBeLessThanOrEqual(10) }, ) }, @@ -193,51 +249,51 @@ describe("Expect", () => { describe("Float", () => { test( "toBeNaN", - _t => { - expect(Js.Math.acos(2.))->Expect.Float.toBeNaN + t => { + t->expect(Js.Math.acos(2.))->Expect.Float.toBeNaN }, ) test( "toBeCloseTo", - _t => { - expect(1.1)->Expect.Float.toBeCloseTo(1.2, 0) + t => { + t->expect(1.1)->Expect.Float.toBeCloseTo(1.2, 0) }, ) test( "toBeGreaterThan", - _t => { - expect(5.)->Expect.Float.toBeGreaterThan(3.) - expect(10.)->Expect.Float.toBeGreaterThan(5.) - expect(0.)->Expect.Float.toBeGreaterThan(-5.) + t => { + t->expect(5.)->Expect.Float.toBeGreaterThan(3.) + t->expect(10.)->Expect.Float.toBeGreaterThan(5.) + t->expect(0.)->Expect.Float.toBeGreaterThan(-5.) }, ) test( "toBeGreaterThanOrEqual", - _t => { - expect(5.)->Expect.Float.toBeGreaterThanOrEqual(3.) - expect(5.)->Expect.Float.toBeGreaterThanOrEqual(5.) - expect(0.)->Expect.Float.toBeGreaterThanOrEqual(-5.) + t => { + t->expect(5.)->Expect.Float.toBeGreaterThanOrEqual(3.) + t->expect(5.)->Expect.Float.toBeGreaterThanOrEqual(5.) + t->expect(0.)->Expect.Float.toBeGreaterThanOrEqual(-5.) }, ) test( "toBeLessThan", - _t => { - expect(3.)->Expect.Float.toBeLessThan(5.) - expect(5.)->Expect.Float.toBeLessThan(10.) - expect(-5.)->Expect.Float.toBeLessThan(0.) + t => { + t->expect(3.)->Expect.Float.toBeLessThan(5.) + t->expect(5.)->Expect.Float.toBeLessThan(10.) + t->expect(-5.)->Expect.Float.toBeLessThan(0.) }, ) test( "toBeLessThanOrEqual", - _t => { - expect(3.)->Expect.Float.toBeLessThanOrEqual(5.) - expect(5.)->Expect.Float.toBeLessThanOrEqual(5.) - expect(-5.)->Expect.Float.toBeLessThanOrEqual(0.) + t => { + t->expect(3.)->Expect.Float.toBeLessThanOrEqual(5.) + t->expect(5.)->Expect.Float.toBeLessThanOrEqual(5.) + t->expect(-5.)->Expect.Float.toBeLessThanOrEqual(0.) }, ) }) @@ -245,29 +301,29 @@ describe("Expect", () => { describe("String", () => { test( "toContain", - _t => { - expect("hello")->Expect.String.toContain("ell") - expect("hello")->Expect.String.toContain("lo") - expect("hello")->Expect.String.toContain("h") - expect("hello")->Expect.not->Expect.String.toContain("x") + t => { + t->expect("hello")->Expect.String.toContain("ell") + t->expect("hello")->Expect.String.toContain("lo") + t->expect("hello")->Expect.String.toContain("h") + t->expect("hello")->Expect.not->Expect.String.toContain("x") }, ) test( "toHaveLength", - _t => { - expect("hello")->Expect.String.toHaveLength(5) - expect("")->Expect.String.toHaveLength(0) - expect("world")->Expect.not->Expect.String.toHaveLength(10) + t => { + t->expect("hello")->Expect.String.toHaveLength(5) + t->expect("")->Expect.String.toHaveLength(0) + t->expect("world")->Expect.not->Expect.String.toHaveLength(10) }, ) test( "toMatch", - _t => { - expect("hello")->Expect.String.toMatch(%re("/h.*o/")) - expect("world")->Expect.String.toMatch(%re("/w.*d/")) - expect("hello")->Expect.not->Expect.String.toMatch(%re("/x.*y/")) + t => { + t->expect("hello")->Expect.String.toMatch(/h.*o/) + t->expect("world")->Expect.String.toMatch(/w.*d/) + t->expect("hello")->Expect.not->Expect.String.toMatch(/x.*y/) }, ) }) @@ -275,40 +331,40 @@ describe("Expect", () => { describe("Array", () => { test( "toContain", - _t => { - expect([1, 2, 3])->Expect.Array.toContain(2) - expect(["hello", "world"])->Expect.Array.toContain("world") - expect([true, false])->Expect.Array.toContain(false) - expect([1, 2, 3])->Expect.not->Expect.Array.toContain(4) + t => { + t->expect([1, 2, 3])->Expect.Array.toContain(2) + t->expect(["hello", "world"])->Expect.Array.toContain("world") + t->expect([true, false])->Expect.Array.toContain(false) + t->expect([1, 2, 3])->Expect.not->Expect.Array.toContain(4) }, ) test( "toContainEqual", - _t => { - expect([1, 2, 3])->Expect.Array.toContainEqual(2) - expect(["hello", "world"])->Expect.Array.toContainEqual("world") - expect([true, false])->Expect.Array.toContainEqual(false) - expect([1, 2, 3])->Expect.not->Expect.Array.toContainEqual(4) + t => { + t->expect([1, 2, 3])->Expect.Array.toContainEqual(2) + t->expect(["hello", "world"])->Expect.Array.toContainEqual("world") + t->expect([true, false])->Expect.Array.toContainEqual(false) + t->expect([1, 2, 3])->Expect.not->Expect.Array.toContainEqual(4) }, ) test( "toHaveLength", - _t => { - expect([1, 2, 3])->Expect.Array.toHaveLength(3) - expect([])->Expect.Array.toHaveLength(0) - expect([1, 2, 3])->Expect.not->Expect.Array.toHaveLength(5) + t => { + t->expect([1, 2, 3])->Expect.Array.toHaveLength(3) + t->expect([])->Expect.Array.toHaveLength(0) + t->expect([1, 2, 3])->Expect.not->Expect.Array.toHaveLength(5) }, ) test( "toMatch", - _t => { - expect([1, 2, 3])->Expect.Array.toMatch([1, 2, 3]) - expect(["hello", "world"])->Expect.Array.toMatch(["hello", "world"]) - expect([true, false])->Expect.Array.toMatch([true, false]) - expect([1, 2, 3])->Expect.not->Expect.Array.toMatch([1, 2]) + t => { + t->expect([1, 2, 3])->Expect.Array.toMatch([1, 2, 3]) + t->expect(["hello", "world"])->Expect.Array.toMatch(["hello", "world"]) + t->expect([true, false])->Expect.Array.toMatch([true, false]) + t->expect([1, 2, 3])->Expect.not->Expect.Array.toMatch([1, 2]) }, ) }) @@ -316,41 +372,41 @@ describe("Expect", () => { describe("List", () => { test( "toContain", - _t => { + 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) + t->expect(value)->Expect.List.toContain(1) + t->expect(value)->Expect.List.toContain(2) + t->expect(value)->Expect.List.toContain(3) + t->expect(value)->Expect.not->Expect.List.toContain(4) }, ) test( "toContainEqual", - _t => { + t => { let value = list{{"property": 1}, {"property": 2}, {"property": 3}} - expect(value)->Expect.List.toContainEqual({"property": 1}) - expect(value)->Expect.List.toContainEqual({"property": 2}) - expect(value)->Expect.List.toContainEqual({"property": 3}) - expect(value)->Expect.not->Expect.List.toContainEqual({"property": 4}) + t->expect(value)->Expect.List.toContainEqual({"property": 1}) + t->expect(value)->Expect.List.toContainEqual({"property": 2}) + t->expect(value)->Expect.List.toContainEqual({"property": 3}) + t->expect(value)->Expect.not->Expect.List.toContainEqual({"property": 4}) }, ) test( "toHaveLength", - _t => { + t => { let value = list{1, 2, 3} - expect(value)->Expect.List.toHaveLength(3) - expect(value)->Expect.not->Expect.List.toHaveLength(5) + t->expect(value)->Expect.List.toHaveLength(3) + t->expect(value)->Expect.not->Expect.List.toHaveLength(5) }, ) test( "toMatch", - _t => { + t => { let value = list{1, 2, 3} - expect(value)->Expect.List.toMatch(list{1, 2, 3}) - expect(value)->Expect.not->Expect.List.toMatch(list{1, 2}) + t->expect(value)->Expect.List.toMatch(list{1, 2, 3}) + t->expect(value)->Expect.not->Expect.List.toMatch(list{1, 2}) }, ) }) @@ -358,36 +414,36 @@ describe("Expect", () => { describe("Dict", () => { test( "toHaveProperty", - _t => { + t => { let dict = Js.Dict.empty() Js.Dict.set(dict, "key", "value") - expect(dict)->Expect.Dict.toHaveProperty("key", "value") - expect(dict)->Expect.not->Expect.Dict.toHaveProperty("nonexistent", "value") + t->expect(dict)->Expect.Dict.toHaveProperty("key", "value") + t->expect(dict)->Expect.not->Expect.Dict.toHaveProperty("nonexistent", "value") }, ) test( "toHaveKey", - _t => { + t => { let dict = Js.Dict.empty() Js.Dict.set(dict, "key", "value") - expect(dict)->Expect.Dict.toHaveKey("key") - expect(dict)->Expect.not->Expect.Dict.toHaveKey("nonexistent") + t->expect(dict)->Expect.Dict.toHaveKey("key") + t->expect(dict)->Expect.not->Expect.Dict.toHaveKey("nonexistent") }, ) test( "toMatch", - _t => { + t => { let dict = Js.Dict.empty() Js.Dict.set(dict, "key1", "value1") Js.Dict.set(dict, "key2", "value2") - expect(dict)->Expect.Dict.toMatch( + t->expect(dict)->Expect.Dict.toMatch( Js.Dict.fromArray([("key1", "value1"), ("key2", "value2")]), ) - expect(dict)->Expect.Dict.toMatch(Js.Dict.fromArray([("key1", "value1")])) - expect(dict)->Expect.Dict.toMatch(Js.Dict.fromArray([("key2", "value2")])) - expect(dict)->Expect.not->Expect.Dict.toMatch(Js.Dict.fromArray([("key1", "value2")])) + t->expect(dict)->Expect.Dict.toMatch(Js.Dict.fromArray([("key1", "value1")])) + t->expect(dict)->Expect.Dict.toMatch(Js.Dict.fromArray([("key2", "value2")])) + t->expect(dict)->Expect.not->Expect.Dict.toMatch(Js.Dict.fromArray([("key1", "value2")])) }, ) }) @@ -395,18 +451,20 @@ describe("Expect", () => { describe("Promise", () => { testAsync( "rejects", - async _t => { + async t => { let promise = () => Js.Promise.reject(%raw(`new Error("hi")`)) - await expect(promise())->Expect.Promise.rejects->Expect.Promise.toThrow(~message="hi") - await expect(promise())->Expect.Promise.rejects->Expect.Promise.toThrowError(~message="hi") + await t->expect(promise())->Expect.Promise.rejects->Expect.Promise.toThrow(~message="hi") + await t->expect(promise()) + ->Expect.Promise.rejects + ->Expect.Promise.toThrowError(~message="hi") }, ) testAsync( "resolves", - async _t => { + async t => { let promise = () => Js.Promise.resolve(1) - await expect(promise())->Expect.Promise.resolves->Expect.Promise.toEqual(1) + await t->expect(promise())->Expect.Promise.resolves->Expect.Promise.toEqual(1) }, ) })