|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +describe("toIncludeSameMembers matcher", () => { |
| 4 | + it("should pass when arrays contain the same elements in different order", () => { |
| 5 | + const array1 = [1, 2, 3]; |
| 6 | + const array2 = [3, 1, 2]; |
| 7 | + |
| 8 | + expect(array1).toIncludeSameMembers(array2); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should pass when arrays contain the same elements in same order", () => { |
| 12 | + const array1 = [1, 2, 3]; |
| 13 | + const array2 = [1, 2, 3]; |
| 14 | + |
| 15 | + expect(array1).toIncludeSameMembers(array2); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should fail when arrays have different lengths", () => { |
| 19 | + const array1 = [1, 2, 3]; |
| 20 | + const array2 = [1, 2]; |
| 21 | + |
| 22 | + expect(() => expect(array1).toIncludeSameMembers(array2)).toThrow(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should fail when arrays contain different elements", () => { |
| 26 | + const array1 = [1, 2, 3]; |
| 27 | + const array2 = [4, 5, 6]; |
| 28 | + |
| 29 | + expect(() => expect(array1).toIncludeSameMembers(array2)).toThrow(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should work with string arrays", () => { |
| 33 | + const array1 = ["apple", "banana", "cherry"]; |
| 34 | + const array2 = ["cherry", "apple", "banana"]; |
| 35 | + |
| 36 | + expect(array1).toIncludeSameMembers(array2); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should work with object arrays", () => { |
| 40 | + const array1 = [{ name: "Alice" }, { name: "Bob" }]; |
| 41 | + const array2 = [{ name: "Bob" }, { name: "Alice" }]; |
| 42 | + |
| 43 | + expect(array1).toIncludeSameMembers(array2); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should work with mixed type arrays", () => { |
| 47 | + const array1 = [1, "hello", { key: "value" }]; |
| 48 | + const array2 = [{ key: "value" }, 1, "hello"]; |
| 49 | + |
| 50 | + expect(array1).toIncludeSameMembers(array2); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should work with empty arrays", () => { |
| 54 | + const array1: unknown[] = []; |
| 55 | + const array2: unknown[] = []; |
| 56 | + |
| 57 | + expect(array1).toIncludeSameMembers(array2); |
| 58 | + }); |
| 59 | +}); |
0 commit comments