diff options
-rw-r--r-- | test/js/bun/test/jest-extended.test.js | 98 |
1 files changed, 51 insertions, 47 deletions
diff --git a/test/js/bun/test/jest-extended.test.js b/test/js/bun/test/jest-extended.test.js index 816863218..7e018d310 100644 --- a/test/js/bun/test/jest-extended.test.js +++ b/test/js/bun/test/jest-extended.test.js @@ -113,23 +113,25 @@ describe("jest-extended", () => { test("toSatisfy()", () => { // Arrow functions const isOdd = value => value % 2 === 1; - const hasLetterH = (value) => value.includes("H"); + const hasLetterH = value => value.includes("H"); expect(1).toSatisfy(isOdd); expect("Hello").toSatisfy(hasLetterH); // Function expressions - function hasBunInAnArray(value) { return value.includes("bun"); } + function hasBunInAnArray(value) { + return value.includes("bun"); + } expect(["bun", "cheese", "patty"]).toSatisfy(hasBunInAnArray); expect(["cheese", "patty"]).not.toSatisfy(hasBunInAnArray); // Inline functions - expect([]).toSatisfy((value) => value.length === 0); + expect([]).toSatisfy(value => value.length === 0); expect([]).not.toSatisfy(value => value.length > 0); // Some other types - const fooIsBar = (value) => value?.foo === "bar"; + const fooIsBar = value => value?.foo === "bar"; expect({ foo: "bar" }).toSatisfy(fooIsBar); expect({ foo: "bun" }).not.toSatisfy(fooIsBar); @@ -137,9 +139,9 @@ describe("jest-extended", () => { // Test errors // @ts-expect-error - expect(() => expect(1).toSatisfy(() => new Error('Bun!'))).toThrow('predicate threw an exception'); + expect(() => expect(1).toSatisfy(() => new Error("Bun!"))).toThrow("predicate threw an exception"); // @ts-expect-error - expect(() => expect(1).not.toSatisfy(() => new Error('Bun!'))).toThrow('predicate threw an exception'); + expect(() => expect(1).not.toSatisfy(() => new Error("Bun!"))).toThrow("predicate threw an exception"); }); // Array @@ -540,47 +542,49 @@ describe("jest-extended", () => { }); test("toIncludeRepeated()", () => { - // 0 - expect("a").toIncludeRepeated("b", 0) - expect("b").not.toIncludeRepeated("b", 0); - - // 1 - expect("abc").toIncludeRepeated("a", 1); - expect("abc").not.toIncludeRepeated("d", 1); - - // Any other number - expect("abc abc abc").toIncludeRepeated("abc", 1); - expect("abc abc abc").toIncludeRepeated("abc", 2); - expect("abc abc abc").toIncludeRepeated("abc", 3); - expect("abc abc abc").not.toIncludeRepeated("abc", 4); - - // Emojis/Unicode - expect("ππ₯³π€ππ₯³").toIncludeRepeated("π", 1); - expect("ππ₯³π€ππ₯³").toIncludeRepeated("π₯³", 2); - expect("ππ₯³π€ππ₯³").not.toIncludeRepeated("π", 3); - expect("ππ₯³π€ππ₯³").not.toIncludeRepeated("πΆβπ«οΈ", 1); - - // Empty string - expect("").not.toIncludeRepeated("a", 1); - - // if toIncludeRepeated() is called with a empty string, it should throw an error or else it segfaults - expect(() => expect("a").not.toIncludeRepeated("", 1)).toThrow() - - // Just to make sure it doesn't throw an error - expect("").not.toIncludeRepeated("a", 1) - expect("").not.toIncludeRepeated("πΆβπ«οΈ", 1) - - // Expect them to throw an error - const tstErr = (y) => { return expect("").toIncludeRepeated("a", y) }; - - expect(() => tstErr(1.23)).toThrow(); - expect(() => tstErr(Infinity)).toThrow(); - expect(() => tstErr(NaN)).toThrow(); - expect(() => tstErr(-0)).toThrow(); // -0 and below (-1, -2, ...) - expect(() => tstErr(null)).toThrow(); - expect(() => tstErr(undefined)).toThrow(); - expect(() => tstErr({})).toThrow(); - }) ; + // 0 + expect("a").toIncludeRepeated("b", 0); + expect("b").not.toIncludeRepeated("b", 0); + + // 1 + expect("abc").toIncludeRepeated("a", 1); + expect("abc").not.toIncludeRepeated("d", 1); + + // Any other number + expect("abc abc abc").toIncludeRepeated("abc", 1); + expect("abc abc abc").toIncludeRepeated("abc", 2); + expect("abc abc abc").toIncludeRepeated("abc", 3); + expect("abc abc abc").not.toIncludeRepeated("abc", 4); + + // Emojis/Unicode + expect("ππ₯³π€ππ₯³").toIncludeRepeated("π", 1); + expect("ππ₯³π€ππ₯³").toIncludeRepeated("π₯³", 2); + expect("ππ₯³π€ππ₯³").not.toIncludeRepeated("π", 3); + expect("ππ₯³π€ππ₯³").not.toIncludeRepeated("πΆβπ«οΈ", 1); + + // Empty string + expect("").not.toIncludeRepeated("a", 1); + + // if toIncludeRepeated() is called with a empty string, it should throw an error or else it segfaults + expect(() => expect("a").not.toIncludeRepeated("", 1)).toThrow(); + + // Just to make sure it doesn't throw an error + expect("").not.toIncludeRepeated("a", 1); + expect("").not.toIncludeRepeated("πΆβπ«οΈ", 1); + + // Expect them to throw an error + const tstErr = y => { + return expect("").toIncludeRepeated("a", y); + }; + + expect(() => tstErr(1.23)).toThrow(); + expect(() => tstErr(Infinity)).toThrow(); + expect(() => tstErr(NaN)).toThrow(); + expect(() => tstErr(-0)).toThrow(); // -0 and below (-1, -2, ...) + expect(() => tstErr(null)).toThrow(); + expect(() => tstErr(undefined)).toThrow(); + expect(() => tstErr({})).toThrow(); + }); // test("toIncludeMultiple()") // test("toEqualIgnoringWhitespace()") |