From 3fbc80f069a0f839ac6835ccb7515cc3c1076721 Mon Sep 17 00:00:00 2001 From: Dom Porada Date: Wed, 26 Nov 2025 16:39:14 +0100 Subject: [PATCH 1/2] Loosen types --- types/matchers.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/matchers.d.ts b/types/matchers.d.ts index 82de01dc..c54052d7 100755 --- a/types/matchers.d.ts +++ b/types/matchers.d.ts @@ -231,7 +231,7 @@ declare namespace matchers { * @see * [testing-library/jest-dom#tohaveattribute](https://github.com/testing-library/jest-dom#tohaveattribute) */ - toHaveAttribute(attr: string, value?: unknown): R + toHaveAttribute(attr: string, value?: any): R /** * @description * Check whether the given element has certain classes within its `class` attribute. @@ -339,7 +339,7 @@ declare namespace matchers { * @see * [testing-library/jest-dom#tohaveformvalues](https://github.com/testing-library/jest-dom#tohaveformvalues) */ - toHaveFormValues(expectedValues: Record): R + toHaveFormValues(expectedValues: Record): R /** * @description * Check if an element has specific css properties with specific values applied. @@ -362,7 +362,7 @@ declare namespace matchers { * @see * [testing-library/jest-dom#tohavestyle](https://github.com/testing-library/jest-dom#tohavestyle) */ - toHaveStyle(css: string | Record): R + toHaveStyle(css: string | Record): R /** * @description * Check whether the given element has a text content or not. From c2861e897ed8c1292e5effc2bce113e5b3ebbf55 Mon Sep 17 00:00:00 2001 From: Dom Porada Date: Wed, 26 Nov 2025 16:47:52 +0100 Subject: [PATCH 2/2] Add tests --- types/__tests__/bun/bun-custom-expect-types.test.ts | 3 +++ types/__tests__/bun/bun-types.test.ts | 3 +++ .../jest-globals/jest-globals-custom-expect-types.test.ts | 3 +++ types/__tests__/jest-globals/jest-globals-types.test.ts | 3 +++ types/__tests__/jest/jest-custom-expect-types.test.ts | 3 +++ types/__tests__/jest/jest-types.test.ts | 3 +++ types/__tests__/vitest/vitest-custom-expect-types.test.ts | 3 +++ types/__tests__/vitest/vitest-types.test.ts | 3 +++ 8 files changed, 24 insertions(+) diff --git a/types/__tests__/bun/bun-custom-expect-types.test.ts b/types/__tests__/bun/bun-custom-expect-types.test.ts index 1467e913..df1a19df 100644 --- a/types/__tests__/bun/bun-custom-expect-types.test.ts +++ b/types/__tests__/bun/bun-custom-expect-types.test.ts @@ -38,6 +38,7 @@ customExpect(element).toContainHTML('body') customExpect(element).toHaveAttribute('attr') customExpect(element).toHaveAttribute('attr', true) customExpect(element).toHaveAttribute('attr', 'yes') +customExpect(element).toHaveAttribute('attr', expect.stringContaining('yes')) customExpect(element).toHaveClass() customExpect(element).toHaveClass('cls1') customExpect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -48,8 +49,10 @@ customExpect(element).toHaveDisplayValue(/str/) customExpect(element).toHaveDisplayValue([/str1/, 'str2']) customExpect(element).toHaveFocus() customExpect(element).toHaveFormValues({foo: 'bar', baz: 1}) +customExpect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) customExpect(element).toHaveStyle('display: block') customExpect(element).toHaveStyle({display: 'block', width: 100}) +customExpect(element).toHaveStyle({display: expect.any(String)}) customExpect(element).toHaveTextContent('Text') customExpect(element).toHaveTextContent(/Text/) customExpect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/bun/bun-types.test.ts b/types/__tests__/bun/bun-types.test.ts index 432dd867..ef77a0db 100644 --- a/types/__tests__/bun/bun-types.test.ts +++ b/types/__tests__/bun/bun-types.test.ts @@ -27,6 +27,7 @@ expect(element).toContainHTML('body') expect(element).toHaveAttribute('attr') expect(element).toHaveAttribute('attr', true) expect(element).toHaveAttribute('attr', 'yes') +expect(element).toHaveAttribute('attr', expect.stringContaining('yes')) expect(element).toHaveClass() expect(element).toHaveClass('cls1') expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -37,8 +38,10 @@ expect(element).toHaveDisplayValue(/str/) expect(element).toHaveDisplayValue([/str1/, 'str2']) expect(element).toHaveFocus() expect(element).toHaveFormValues({foo: 'bar', baz: 1}) +expect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) expect(element).toHaveStyle('display: block') expect(element).toHaveStyle({display: 'block', width: 100}) +expect(element).toHaveStyle({display: expect.any(String)}) expect(element).toHaveTextContent('Text') expect(element).toHaveTextContent(/Text/) expect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/jest-globals/jest-globals-custom-expect-types.test.ts b/types/__tests__/jest-globals/jest-globals-custom-expect-types.test.ts index 96034dc1..6eefe633 100644 --- a/types/__tests__/jest-globals/jest-globals-custom-expect-types.test.ts +++ b/types/__tests__/jest-globals/jest-globals-custom-expect-types.test.ts @@ -37,6 +37,7 @@ customExpect(element).toContainHTML('body') customExpect(element).toHaveAttribute('attr') customExpect(element).toHaveAttribute('attr', true) customExpect(element).toHaveAttribute('attr', 'yes') +customExpect(element).toHaveAttribute('attr', expect.stringContaining('yes')) customExpect(element).toHaveClass() customExpect(element).toHaveClass('cls1') customExpect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -47,8 +48,10 @@ customExpect(element).toHaveDisplayValue(/str/) customExpect(element).toHaveDisplayValue([/str1/, 'str2']) customExpect(element).toHaveFocus() customExpect(element).toHaveFormValues({foo: 'bar', baz: 1}) +customExpect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) customExpect(element).toHaveStyle('display: block') customExpect(element).toHaveStyle({display: 'block', width: 100}) +customExpect(element).toHaveStyle({display: expect.any(String)}) customExpect(element).toHaveTextContent('Text') customExpect(element).toHaveTextContent(/Text/) customExpect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/jest-globals/jest-globals-types.test.ts b/types/__tests__/jest-globals/jest-globals-types.test.ts index 150f8250..88e0c503 100644 --- a/types/__tests__/jest-globals/jest-globals-types.test.ts +++ b/types/__tests__/jest-globals/jest-globals-types.test.ts @@ -27,6 +27,7 @@ expect(element).toContainHTML('body') expect(element).toHaveAttribute('attr') expect(element).toHaveAttribute('attr', true) expect(element).toHaveAttribute('attr', 'yes') +expect(element).toHaveAttribute('attr', expect.stringContaining('yes')) expect(element).toHaveClass() expect(element).toHaveClass('cls1') expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -37,8 +38,10 @@ expect(element).toHaveDisplayValue(/str/) expect(element).toHaveDisplayValue([/str1/, 'str2']) expect(element).toHaveFocus() expect(element).toHaveFormValues({foo: 'bar', baz: 1}) +expect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) expect(element).toHaveStyle('display: block') expect(element).toHaveStyle({display: 'block', width: 100}) +expect(element).toHaveStyle({display: expect.any(String)}) expect(element).toHaveTextContent('Text') expect(element).toHaveTextContent(/Text/) expect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/jest/jest-custom-expect-types.test.ts b/types/__tests__/jest/jest-custom-expect-types.test.ts index 6b64b8e5..14f84553 100644 --- a/types/__tests__/jest/jest-custom-expect-types.test.ts +++ b/types/__tests__/jest/jest-custom-expect-types.test.ts @@ -36,6 +36,7 @@ customExpect(element).toContainHTML('body') customExpect(element).toHaveAttribute('attr') customExpect(element).toHaveAttribute('attr', true) customExpect(element).toHaveAttribute('attr', 'yes') +customExpect(element).toHaveAttribute('attr', expect.stringContaining('yes')) customExpect(element).toHaveClass() customExpect(element).toHaveClass('cls1') customExpect(element).toHaveClass(/cls/) @@ -47,8 +48,10 @@ customExpect(element).toHaveDisplayValue(/str/) customExpect(element).toHaveDisplayValue([/str1/, 'str2']) customExpect(element).toHaveFocus() customExpect(element).toHaveFormValues({foo: 'bar', baz: 1}) +customExpect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) customExpect(element).toHaveStyle('display: block') customExpect(element).toHaveStyle({display: 'block', width: 100}) +customExpect(element).toHaveStyle({display: expect.any(String)}) customExpect(element).toHaveTextContent('Text') customExpect(element).toHaveTextContent(/Text/) customExpect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/jest/jest-types.test.ts b/types/__tests__/jest/jest-types.test.ts index d9596c67..a71dc691 100644 --- a/types/__tests__/jest/jest-types.test.ts +++ b/types/__tests__/jest/jest-types.test.ts @@ -26,6 +26,7 @@ expect(element).toContainHTML('body') expect(element).toHaveAttribute('attr') expect(element).toHaveAttribute('attr', true) expect(element).toHaveAttribute('attr', 'yes') +expect(element).toHaveAttribute('attr', expect.stringContaining('yes')) expect(element).toHaveClass() expect(element).toHaveClass('cls1') expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -36,8 +37,10 @@ expect(element).toHaveDisplayValue(/str/) expect(element).toHaveDisplayValue([/str1/, 'str2']) expect(element).toHaveFocus() expect(element).toHaveFormValues({foo: 'bar', baz: 1}) +expect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) expect(element).toHaveStyle('display: block') expect(element).toHaveStyle({display: 'block', width: 100}) +expect(element).toHaveStyle({display: expect.any(String)}) expect(element).toHaveTextContent('Text') expect(element).toHaveTextContent(/Text/) expect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/vitest/vitest-custom-expect-types.test.ts b/types/__tests__/vitest/vitest-custom-expect-types.test.ts index e9008966..bc4aa5cb 100644 --- a/types/__tests__/vitest/vitest-custom-expect-types.test.ts +++ b/types/__tests__/vitest/vitest-custom-expect-types.test.ts @@ -37,6 +37,7 @@ customExpect(element).toContainHTML('body') customExpect(element).toHaveAttribute('attr') customExpect(element).toHaveAttribute('attr', true) customExpect(element).toHaveAttribute('attr', 'yes') +customExpect(element).toHaveAttribute('attr', expect.stringContaining('yes')) customExpect(element).toHaveClass() customExpect(element).toHaveClass('cls1') customExpect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -47,8 +48,10 @@ customExpect(element).toHaveDisplayValue(/str/) customExpect(element).toHaveDisplayValue([/str1/, 'str2']) customExpect(element).toHaveFocus() customExpect(element).toHaveFormValues({foo: 'bar', baz: 1}) +customExpect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) customExpect(element).toHaveStyle('display: block') customExpect(element).toHaveStyle({display: 'block', width: 100}) +customExpect(element).toHaveStyle({display: expect.any(String)}) customExpect(element).toHaveTextContent('Text') customExpect(element).toHaveTextContent(/Text/) customExpect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) diff --git a/types/__tests__/vitest/vitest-types.test.ts b/types/__tests__/vitest/vitest-types.test.ts index 7a90be05..cb246685 100644 --- a/types/__tests__/vitest/vitest-types.test.ts +++ b/types/__tests__/vitest/vitest-types.test.ts @@ -27,6 +27,7 @@ expect(element).toContainHTML('body') expect(element).toHaveAttribute('attr') expect(element).toHaveAttribute('attr', true) expect(element).toHaveAttribute('attr', 'yes') +expect(element).toHaveAttribute('attr', expect.stringContaining('yes')) expect(element).toHaveClass() expect(element).toHaveClass('cls1') expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') @@ -37,8 +38,10 @@ expect(element).toHaveDisplayValue(/str/) expect(element).toHaveDisplayValue([/str1/, 'str2']) expect(element).toHaveFocus() expect(element).toHaveFormValues({foo: 'bar', baz: 1}) +expect(element).toHaveFormValues({foo: 'bar', baz: expect.any(Number)}) expect(element).toHaveStyle('display: block') expect(element).toHaveStyle({display: 'block', width: 100}) +expect(element).toHaveStyle({display: expect.any(String)}) expect(element).toHaveTextContent('Text') expect(element).toHaveTextContent(/Text/) expect(element).toHaveTextContent('Text', {normalizeWhitespace: true})