diff --git a/__tests__/expect_test.ml b/__tests__/expect_test.ml index 7bf69e0..cd7118d 100644 --- a/__tests__/expect_test.ml +++ b/__tests__/expect_test.ml @@ -1,5 +1,9 @@ open Jest +type test_record = { + value: string +} + let () = describe "Expect" (fun () -> @@ -23,6 +27,8 @@ describe "Expect" (fun () -> expect [| "a"; "b"; "c" |] |> toBeSupersetOf [| "a"; "c" |]); test "toContain" (fun () -> expect [| "a"; "b"; "c" |] |> toContain "b"); + test "toContainEqual" (fun () -> + expect [| {value = "a"}; {value = "b"}; {value = "c"} |] |> toContainEqual {value = "b"}); test "toContainString" (fun () -> expect "banana" |> toContainString "nana"); test "toHaveLength" (fun () -> @@ -69,6 +75,8 @@ describe "Expect" (fun () -> expect [| "a"; "b"; "c" |] |> not_ |> toBeSupersetOf [| "a"; "d" |]); test "not toContain" (fun () -> expect [| "a"; "b"; "c" |] |> not_ |> toContain "d"); + test "not toContainEqual" (fun () -> + expect [| {value = "a"}; {value = "b"}; {value = "c"} |] |> not_ |> toContainEqual {value = "d"}); test "not toContainString" (fun () -> expect "banana" |> not_ |> toContainString "nanan"); test "not toHaveLength" (fun () -> @@ -146,4 +154,4 @@ describe "ExpectJs" (fun () -> expect [%obj { foo = 0; bar = true }] |> not_ |> toContainProperties [| "foo"; "zoo" |]); test "not toMatchObject" (fun () -> expect [%obj { a = 1; b = 2; c = 3 }] |> not_ |> toMatchObject [%obj { a = 1; c = 2 }]); -); \ No newline at end of file +); diff --git a/lib/js/src/jest.js b/lib/js/src/jest.js index e3fe8ee..c2dae92 100644 --- a/lib/js/src/jest.js +++ b/lib/js/src/jest.js @@ -45,131 +45,131 @@ function affirm(param) { var match$2 = match[1]; return expect(match$2[0]).not.toContain(match$2[1]); } - case /* ArrayLength */2 : + case /* ArrayContainsEqual */2 : var match$3 = param[0]; if (match$3[0] >= 826472012) { var match$4 = match$3[1]; - return expect(match$4[0]).toHaveLength(match$4[1]); + return expect(match$4[0]).toContainEqual(match$4[1]); } else { var match$5 = match$3[1]; - return expect(match$5[0]).not.toHaveLength(match$5[1]); + return expect(match$5[0]).not.toContainEqual(match$5[1]); } - case /* ArraySuperset */3 : + case /* ArrayLength */3 : var match$6 = param[0]; if (match$6[0] >= 826472012) { var match$7 = match$6[1]; - return expect(match$7[0]).toEqual(expect.arrayContaining(match$7[1])); + return expect(match$7[0]).toHaveLength(match$7[1]); } else { var match$8 = match$6[1]; - return expect(match$8[0]).not.toEqual(expect.arrayContaining(match$8[1])); + return expect(match$8[0]).not.toHaveLength(match$8[1]); } - case /* Be */4 : + case /* ArraySuperset */4 : var match$9 = param[0]; if (match$9[0] >= 826472012) { var match$10 = match$9[1]; - return expect(match$10[0]).toBe(match$10[1]); + return expect(match$10[0]).toEqual(expect.arrayContaining(match$10[1])); } else { var match$11 = match$9[1]; - return expect(match$11[0]).not.toBe(match$11[1]); + return expect(match$11[0]).not.toEqual(expect.arrayContaining(match$11[1])); } - case /* Equal */5 : + case /* Be */5 : var match$12 = param[0]; if (match$12[0] >= 826472012) { var match$13 = match$12[1]; - return expect(match$13[0]).toEqual(match$13[1]); + return expect(match$13[0]).toBe(match$13[1]); } else { var match$14 = match$12[1]; - return expect(match$14[0]).not.toEqual(match$14[1]); + return expect(match$14[0]).not.toBe(match$14[1]); } - case /* FloatCloseTo */6 : + case /* Equal */6 : var match$15 = param[0]; if (match$15[0] >= 826472012) { var match$16 = match$15[1]; - return expect(match$16[0]).toBeCloseTo(match$16[1], Js_undefined.fromOption(match$16[2])); + return expect(match$16[0]).toEqual(match$16[1]); } else { var match$17 = match$15[1]; - return expect(match$17[0]).not.toBeCloseTo(match$17[1], Js_undefined.fromOption(match$17[2])); + return expect(match$17[0]).not.toEqual(match$17[1]); } - case /* GreaterThan */7 : + case /* FloatCloseTo */7 : var match$18 = param[0]; if (match$18[0] >= 826472012) { var match$19 = match$18[1]; - return expect(match$19[0]).toBeGreaterThan(match$19[1]); + return expect(match$19[0]).toBeCloseTo(match$19[1], Js_undefined.fromOption(match$19[2])); } else { var match$20 = match$18[1]; - return expect(match$20[0]).not.toBeGreaterThan(match$20[1]); + return expect(match$20[0]).not.toBeCloseTo(match$20[1], Js_undefined.fromOption(match$20[2])); } - case /* GreaterThanOrEqual */8 : + case /* GreaterThan */8 : var match$21 = param[0]; if (match$21[0] >= 826472012) { var match$22 = match$21[1]; - return expect(match$22[0]).toBeGreaterThanOrEqual(match$22[1]); + return expect(match$22[0]).toBeGreaterThan(match$22[1]); } else { var match$23 = match$21[1]; - return expect(match$23[0]).not.toBeGreaterThanOrEqual(match$23[1]); + return expect(match$23[0]).not.toBeGreaterThan(match$23[1]); } - case /* LessThan */9 : + case /* GreaterThanOrEqual */9 : var match$24 = param[0]; if (match$24[0] >= 826472012) { var match$25 = match$24[1]; - return expect(match$25[0]).toBeLessThan(match$25[1]); + return expect(match$25[0]).toBeGreaterThanOrEqual(match$25[1]); } else { var match$26 = match$24[1]; - return expect(match$26[0]).not.toBeLessThan(match$26[1]); + return expect(match$26[0]).not.toBeGreaterThanOrEqual(match$26[1]); } - case /* LessThanOrEqual */10 : + case /* LessThan */10 : var match$27 = param[0]; if (match$27[0] >= 826472012) { var match$28 = match$27[1]; - return expect(match$28[0]).toBeLessThanOrEqual(match$28[1]); + return expect(match$28[0]).toBeLessThan(match$28[1]); } else { var match$29 = match$27[1]; - return expect(match$29[0]).not.toBeLessThanOrEqual(match$29[1]); + return expect(match$29[0]).not.toBeLessThan(match$29[1]); } - case /* StringContains */11 : + case /* LessThanOrEqual */11 : var match$30 = param[0]; if (match$30[0] >= 826472012) { var match$31 = match$30[1]; - return expect(match$31[0]).toEqual(expect.stringContaining(match$31[1])); + return expect(match$31[0]).toBeLessThanOrEqual(match$31[1]); } else { var match$32 = match$30[1]; - return expect(match$32[0]).not.toEqual(expect.stringContaining(match$32[1])); + return expect(match$32[0]).not.toBeLessThanOrEqual(match$32[1]); } - case /* StringMatch */12 : + case /* StringContains */12 : var match$33 = param[0]; if (match$33[0] >= 826472012) { var match$34 = match$33[1]; - return expect(match$34[0]).toMatch(match$34[1]); + return expect(match$34[0]).toEqual(expect.stringContaining(match$34[1])); } else { var match$35 = match$33[1]; - return expect(match$35[0]).not.toMatch(match$35[1]); + return expect(match$35[0]).not.toEqual(expect.stringContaining(match$35[1])); } - case /* Throws */13 : + case /* StringMatch */13 : var match$36 = param[0]; if (match$36[0] >= 826472012) { - return expect(match$36[1]).toThrow(); + var match$37 = match$36[1]; + return expect(match$37[0]).toMatch(match$37[1]); } else { - return expect(match$36[1]).not.toThrow(); + var match$38 = match$36[1]; + return expect(match$38[0]).not.toMatch(match$38[1]); } - case /* ThrowsException */14 : - var match$37 = param[0]; - if (match$37[0] >= 826472012) { - var match$38 = match$37[1]; - return expect(match$38[0]).toThrow(String(match$38[1])); + case /* Throws */14 : + var match$39 = param[0]; + if (match$39[0] >= 826472012) { + return expect(match$39[1]).toThrow(); } else { - var match$39 = match$37[1]; - return expect(match$39[0]).not.toThrow(String(match$39[1])); + return expect(match$39[1]).not.toThrow(); } - case /* ThrowsMessage */15 : + case /* ThrowsException */15 : var match$40 = param[0]; if (match$40[0] >= 826472012) { var match$41 = match$40[1]; - return expect(match$41[0]).toThrow(match$41[1]); + return expect(match$41[0]).toThrow(String(match$41[1])); } else { var match$42 = match$40[1]; - return expect(match$42[0]).not.toThrow(match$42[1]); + return expect(match$42[0]).not.toThrow(String(match$42[1])); } - case /* ThrowsMessageRe */16 : + case /* ThrowsMessage */16 : var match$43 = param[0]; if (match$43[0] >= 826472012) { var match$44 = match$43[1]; @@ -178,66 +178,75 @@ function affirm(param) { var match$45 = match$43[1]; return expect(match$45[0]).not.toThrow(match$45[1]); } - case /* MatchInlineSnapshot */17 : - return expect(param[0]).toMatchInlineSnapshot(param[1]); - case /* MatchSnapshot */18 : - return expect(param[0]).toMatchSnapshot(); - case /* MatchSnapshotName */19 : - return expect(param[0]).toMatchSnapshot(param[1]); - case /* ThrowsMatchSnapshot */20 : - return expect(param[0]).toThrowErrorMatchingSnapshot(); - case /* Defined */21 : + case /* ThrowsMessageRe */17 : var match$46 = param[0]; if (match$46[0] >= 826472012) { - return expect(match$46[1]).toBeDefined(); + var match$47 = match$46[1]; + return expect(match$47[0]).toThrow(match$47[1]); } else { - return expect(match$46[1]).not.toBeDefined(); + var match$48 = match$46[1]; + return expect(match$48[0]).not.toThrow(match$48[1]); } - case /* Falsy */22 : - var match$47 = param[0]; - if (match$47[0] >= 826472012) { - return expect(match$47[1]).toBeFalsy(); - } else { - return expect(match$47[1]).not.toBeFalsy(); - } - case /* Null */23 : - var match$48 = param[0]; - if (match$48[0] >= 826472012) { - return expect(match$48[1]).toBeNull(); - } else { - return expect(match$48[1]).not.toBeNull(); - } - case /* Truthy */24 : + case /* MatchInlineSnapshot */18 : + return expect(param[0]).toMatchInlineSnapshot(param[1]); + case /* MatchSnapshot */19 : + return expect(param[0]).toMatchSnapshot(); + case /* MatchSnapshotName */20 : + return expect(param[0]).toMatchSnapshot(param[1]); + case /* ThrowsMatchSnapshot */21 : + return expect(param[0]).toThrowErrorMatchingSnapshot(); + case /* Defined */22 : var match$49 = param[0]; if (match$49[0] >= 826472012) { - return expect(match$49[1]).toBeTruthy(); + return expect(match$49[1]).toBeDefined(); } else { - return expect(match$49[1]).not.toBeTruthy(); + return expect(match$49[1]).not.toBeDefined(); } - case /* Undefined */25 : + case /* Falsy */23 : var match$50 = param[0]; if (match$50[0] >= 826472012) { - return expect(match$50[1]).toBeUndefined(); + return expect(match$50[1]).toBeFalsy(); } else { - return expect(match$50[1]).not.toBeUndefined(); + return expect(match$50[1]).not.toBeFalsy(); } - case /* ObjectContains */26 : + case /* Null */24 : var match$51 = param[0]; if (match$51[0] >= 826472012) { - var match$52 = match$51[1]; - return expect(match$52[0]).toEqual(objectContaining(match$52[1])); + return expect(match$51[1]).toBeNull(); } else { - var match$53 = match$51[1]; - return expect(match$53[0]).not.toEqual(objectContaining(match$53[1])); + return expect(match$51[1]).not.toBeNull(); } - case /* ObjectMatch */27 : + case /* Truthy */25 : + var match$52 = param[0]; + if (match$52[0] >= 826472012) { + return expect(match$52[1]).toBeTruthy(); + } else { + return expect(match$52[1]).not.toBeTruthy(); + } + case /* Undefined */26 : + var match$53 = param[0]; + if (match$53[0] >= 826472012) { + return expect(match$53[1]).toBeUndefined(); + } else { + return expect(match$53[1]).not.toBeUndefined(); + } + case /* ObjectContains */27 : var match$54 = param[0]; if (match$54[0] >= 826472012) { var match$55 = match$54[1]; - return expect(match$55[0]).toMatchObject(match$55[1]); + return expect(match$55[0]).toEqual(objectContaining(match$55[1])); } else { var match$56 = match$54[1]; - return expect(match$56[0]).not.toMatchObject(match$56[1]); + return expect(match$56[0]).not.toEqual(objectContaining(match$56[1])); + } + case /* ObjectMatch */28 : + var match$57 = param[0]; + if (match$57[0] >= 826472012) { + var match$58 = match$57[1]; + return expect(match$58[0]).toMatchObject(match$58[1]); + } else { + var match$59 = match$57[1]; + return expect(match$59[0]).not.toMatchObject(match$59[1]); } } @@ -465,7 +474,7 @@ function expectFn(f, a) { } function toBe(b, p) { - return /* Be */Block.__(4, [mapMod((function (a) { + return /* Be */Block.__(5, [mapMod((function (a) { return /* tuple */[ a, b @@ -474,7 +483,7 @@ function toBe(b, p) { } function toBeCloseTo(b, p) { - return /* FloatCloseTo */Block.__(6, [mapMod((function (a) { + return /* FloatCloseTo */Block.__(7, [mapMod((function (a) { return /* tuple */[ a, b, @@ -484,7 +493,7 @@ function toBeCloseTo(b, p) { } function toBeSoCloseTo(b, digits, p) { - return /* FloatCloseTo */Block.__(6, [mapMod((function (a) { + return /* FloatCloseTo */Block.__(7, [mapMod((function (a) { return /* tuple */[ a, b, @@ -494,7 +503,7 @@ function toBeSoCloseTo(b, digits, p) { } function toBeGreaterThan(b, p) { - return /* GreaterThan */Block.__(7, [mapMod((function (a) { + return /* GreaterThan */Block.__(8, [mapMod((function (a) { return /* tuple */[ a, b @@ -503,7 +512,7 @@ function toBeGreaterThan(b, p) { } function toBeGreaterThanOrEqual(b, p) { - return /* GreaterThanOrEqual */Block.__(8, [mapMod((function (a) { + return /* GreaterThanOrEqual */Block.__(9, [mapMod((function (a) { return /* tuple */[ a, b @@ -512,7 +521,7 @@ function toBeGreaterThanOrEqual(b, p) { } function toBeLessThan(b, p) { - return /* LessThan */Block.__(9, [mapMod((function (a) { + return /* LessThan */Block.__(10, [mapMod((function (a) { return /* tuple */[ a, b @@ -521,7 +530,7 @@ function toBeLessThan(b, p) { } function toBeLessThanOrEqual(b, p) { - return /* LessThanOrEqual */Block.__(10, [mapMod((function (a) { + return /* LessThanOrEqual */Block.__(11, [mapMod((function (a) { return /* tuple */[ a, b @@ -530,7 +539,7 @@ function toBeLessThanOrEqual(b, p) { } function toBeSupersetOf(b, p) { - return /* ArraySuperset */Block.__(3, [mapMod((function (a) { + return /* ArraySuperset */Block.__(4, [mapMod((function (a) { return /* tuple */[ a, b @@ -547,8 +556,17 @@ function toContain(b, p) { }), p)]); } +function toContainEqual(b, p) { + return /* ArrayContainsEqual */Block.__(2, [mapMod((function (a) { + return /* tuple */[ + a, + b + ]; + }), p)]); +} + function toContainString(b, p) { - return /* StringContains */Block.__(11, [mapMod((function (a) { + return /* StringContains */Block.__(12, [mapMod((function (a) { return /* tuple */[ a, b @@ -557,7 +575,7 @@ function toContainString(b, p) { } function toEqual(b, p) { - return /* Equal */Block.__(5, [mapMod((function (a) { + return /* Equal */Block.__(6, [mapMod((function (a) { return /* tuple */[ a, b @@ -566,7 +584,7 @@ function toEqual(b, p) { } function toHaveLength(l, p) { - return /* ArrayLength */Block.__(2, [mapMod((function (a) { + return /* ArrayLength */Block.__(3, [mapMod((function (a) { return /* tuple */[ a, l @@ -575,7 +593,7 @@ function toHaveLength(l, p) { } function toMatch(s, p) { - return /* StringMatch */Block.__(12, [mapMod((function (a) { + return /* StringMatch */Block.__(13, [mapMod((function (a) { return /* tuple */[ a, new RegExp(s) @@ -584,14 +602,14 @@ function toMatch(s, p) { } function toMatchInlineSnapshot(inlineSnapshot, param) { - return /* MatchInlineSnapshot */Block.__(17, [ + return /* MatchInlineSnapshot */Block.__(18, [ param[1], inlineSnapshot ]); } function toMatchRe(re, p) { - return /* StringMatch */Block.__(12, [mapMod((function (a) { + return /* StringMatch */Block.__(13, [mapMod((function (a) { return /* tuple */[ a, re @@ -600,26 +618,26 @@ function toMatchRe(re, p) { } function toMatchSnapshot(param) { - return /* MatchSnapshot */Block.__(18, [param[1]]); + return /* MatchSnapshot */Block.__(19, [param[1]]); } function toMatchSnapshotWithName(name, param) { - return /* MatchSnapshotName */Block.__(19, [ + return /* MatchSnapshotName */Block.__(20, [ param[1], name ]); } function toThrow(f) { - return /* Throws */Block.__(13, [f]); + return /* Throws */Block.__(14, [f]); } function toThrowErrorMatchingSnapshot(param) { - return /* ThrowsMatchSnapshot */Block.__(20, [param[1]]); + return /* ThrowsMatchSnapshot */Block.__(21, [param[1]]); } function toThrowException(e, p) { - return /* ThrowsException */Block.__(14, [mapMod((function (f) { + return /* ThrowsException */Block.__(15, [mapMod((function (f) { return /* tuple */[ f, e @@ -628,7 +646,7 @@ function toThrowException(e, p) { } function toThrowMessage(message, p) { - return /* ThrowsMessage */Block.__(15, [mapMod((function (f) { + return /* ThrowsMessage */Block.__(16, [mapMod((function (f) { return /* tuple */[ f, message @@ -637,7 +655,7 @@ function toThrowMessage(message, p) { } function toThrowMessageRe(re, p) { - return /* ThrowsMessageRe */Block.__(16, [mapMod((function (f) { + return /* ThrowsMessageRe */Block.__(17, [mapMod((function (f) { return /* tuple */[ f, re @@ -707,6 +725,7 @@ var Expect = { toBeLessThanOrEqual: toBeLessThanOrEqual, toBeSupersetOf: toBeSupersetOf, toContain: toContain, + toContainEqual: toContainEqual, toContainString: toContainString, toEqual: toEqual, toHaveLength: toHaveLength, @@ -726,27 +745,27 @@ var Expect = { }; function toBeDefined(a) { - return /* Defined */Block.__(21, [a]); + return /* Defined */Block.__(22, [a]); } function toBeFalsy(a) { - return /* Falsy */Block.__(22, [a]); + return /* Falsy */Block.__(23, [a]); } function toBeNull(a) { - return /* Null */Block.__(23, [a]); + return /* Null */Block.__(24, [a]); } function toBeTruthy(a) { - return /* Truthy */Block.__(24, [a]); + return /* Truthy */Block.__(25, [a]); } function toBeUndefined(a) { - return /* Undefined */Block.__(25, [a]); + return /* Undefined */Block.__(26, [a]); } function toContainProperties(props, p) { - return /* ObjectContains */Block.__(26, [mapMod((function (a) { + return /* ObjectContains */Block.__(27, [mapMod((function (a) { return /* tuple */[ a, props @@ -755,7 +774,7 @@ function toContainProperties(props, p) { } function toMatchObject(b, p) { - return /* ObjectMatch */Block.__(27, [mapMod((function (a) { + return /* ObjectMatch */Block.__(28, [mapMod((function (a) { return /* tuple */[ a, b @@ -775,6 +794,7 @@ var ExpectJs = { toBeLessThanOrEqual: toBeLessThanOrEqual, toBeSupersetOf: toBeSupersetOf, toContain: toContain, + toContainEqual: toContainEqual, toContainString: toContainString, toEqual: toEqual, toHaveLength: toHaveLength, diff --git a/src/jest.ml b/src/jest.ml index 6315142..8cf141a 100644 --- a/src/jest.ml +++ b/src/jest.ml @@ -12,6 +12,7 @@ type assertion = | Fail : string -> assertion | ArrayContains : ('a array * 'a) modifier -> assertion +| ArrayContainsEqual : ('a array * 'a) modifier -> assertion | ArrayLength : ('a array * int) modifier -> assertion | ArraySuperset : ('a array * 'a array) modifier -> assertion | Be : ('a * 'a) modifier -> assertion @@ -76,6 +77,8 @@ end = struct | ArrayContains `Just (a, b) -> (expect a) ## toContain b | ArrayContains `Not (a, b) -> (expect a) ## not ## toContain b + | ArrayContainsEqual `Just (a, b) -> (expect a) ## toContainEqual b + | ArrayContainsEqual `Not (a, b) -> (expect a) ## not ## toContainEqual b | ArrayLength `Just (a, l) -> (expect a) ## toHaveLength l | ArrayLength `Not (a, l) -> (expect a) ## not ## toHaveLength l | ArraySuperset `Just (a, b) -> (expect a) ## toEqual (arrayContaining b) @@ -326,6 +329,9 @@ module Expect = struct let toContain b p = ArrayContains (mapMod (fun a -> (a, b)) p) + let toContainEqual b p = + ArrayContainsEqual (mapMod (fun a -> (a, b)) p) + (** replaces expect.stringContaining *) let toContainString b p = StringContains (mapMod (fun a -> (a, b)) p) diff --git a/src/jest.mli b/src/jest.mli index 5a2da15..237d86a 100644 --- a/src/jest.mli +++ b/src/jest.mli @@ -106,6 +106,7 @@ module Expect : sig val toBeLessThanOrEqual : 'a -> [< 'a partial] -> assertion val toBeSupersetOf : 'a array -> [< 'a array partial] -> assertion val toContain : 'a -> [< 'a array partial] -> assertion + val toContainEqual : 'a -> [< 'a array partial] -> assertion val toContainString : string -> [< string partial] -> assertion val toEqual : 'a -> [< 'a partial] -> assertion val toHaveLength : int -> [< 'a array partial] -> assertion