Skip to content

Commit 872ba18

Browse files
authored
Merge pull request #6 from NoamGaash/fix/strict-types
fix: make types strictier
2 parents 8f99e3a + 9a76d14 commit 872ba18

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/matchers/arrays.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Matchers } from "../types";
1+
import { ExpectMatcherState } from "playwright/test";
22

3-
export const matchers: Matchers = {
4-
toHaveDuplications(received: Array<unknown>) {
3+
export const matchers = {
4+
toHaveDuplications(this: ExpectMatcherState, received: Array<unknown>) {
55
const dups = received.toSorted().filter((item, index, arr) => item === arr[index - 1]);
66
const uniqueDups = [...new Set(dups)];
77
const pass = uniqueDups.length > 0;

src/types.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/types.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test } from "@playwright/test";
2+
import { expect } from "../src";
3+
import { describe } from "node:test";
4+
5+
test.describe("types", () => {
6+
describe("valid", () => {
7+
test("toHaveDuplications", async () => {
8+
expect([1, 2, 2, 3]).toHaveDuplications();
9+
});
10+
});
11+
12+
describe("invalid", () => {
13+
// @ts-expect-error - invalid receiver type
14+
expect("sdfsfsd").toHaveDuplication();
15+
// @ts-expect-error - invalid matcher
16+
void expect("sdfsfsd").thisAssertionDoesNotExist;
17+
// @ts-expect-error - invalid argument type
18+
expect([1, 2, 3]).toHaveDuplications(123);
19+
});
20+
});

0 commit comments

Comments
 (0)