diff --git a/code/lib/test/package.json b/code/lib/test/package.json index e4cd5c5f4f63..c028e1663218 100644 --- a/code/lib/test/package.json +++ b/code/lib/test/package.json @@ -43,8 +43,8 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/instrumenter": "workspace:^", "@storybook/client-logger": "workspace:^", + "@storybook/instrumenter": "workspace:^", "@testing-library/dom": "^9.3.1", "@testing-library/jest-dom": "^6.1.3", "@testing-library/user-event": "^14.4.3", diff --git a/code/lib/test/src/expect.ts b/code/lib/test/src/expect.ts index 04d4a05dc366..d277380a3596 100644 --- a/code/lib/test/src/expect.ts +++ b/code/lib/test/src/expect.ts @@ -15,10 +15,13 @@ import { setState, } from '@vitest/expect'; import * as matchers from '@testing-library/jest-dom/matchers'; +import type { TestingLibraryMatchers } from '@testing-library/jest-dom/types/matchers'; import type { PromisifyObject } from './utils'; // We only expose the jest compatible API for now -export interface Assertion extends PromisifyObject> { +export interface Assertion + extends PromisifyObject>, + TestingLibraryMatchers, Promise> { toHaveBeenCalledOnce(): Promise; toSatisfy(matcher: (value: E) => boolean, message?: string): Promise; resolves: Assertion; @@ -80,7 +83,8 @@ export function createExpect() { expect.getState().assertionCalls }` ); - if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions); + if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') + Error.captureStackTrace(errorGen(), assertions); expect.setState({ expectedAssertionsNumber: expected, @@ -90,7 +94,8 @@ export function createExpect() { function hasAssertions() { const error = new Error('expected any number of assertion, but got none'); - if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions); + if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') + Error.captureStackTrace(error, hasAssertions); expect.setState({ isExpectingAssertions: true, diff --git a/code/package.json b/code/package.json index 16938008257f..53eb69e25862 100644 --- a/code/package.json +++ b/code/package.json @@ -80,7 +80,6 @@ ], "resolutions": { "@playwright/test": "1.36.0", - "@testing-library/jest-dom": "^5.11.9", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/experimental-utils": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", diff --git a/code/yarn.lock b/code/yarn.lock index a799f401d8aa..f6555323e6b9 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -24,7 +24,7 @@ __metadata: languageName: node linkType: hard -"@adobe/css-tools@npm:^4.0.1": +"@adobe/css-tools@npm:^4.0.1, @adobe/css-tools@npm:^4.3.0": version: 4.3.1 resolution: "@adobe/css-tools@npm:4.3.1" checksum: 05672719b544cc0c21ae3ed0eb6349bf458e9d09457578eeeb07cf0f696469ac6417e9c9be1b129e5d6a18098a061c1db55b2275591760ef30a79822436fcbfa @@ -8829,7 +8829,7 @@ __metadata: languageName: node linkType: hard -"@testing-library/jest-dom@npm:^5.11.9": +"@testing-library/jest-dom@npm:^5.11.9, @testing-library/jest-dom@npm:^5.16.2": version: 5.17.0 resolution: "@testing-library/jest-dom@npm:5.17.0" dependencies: @@ -8846,6 +8846,36 @@ __metadata: languageName: node linkType: hard +"@testing-library/jest-dom@npm:^6.1.3": + version: 6.1.3 + resolution: "@testing-library/jest-dom@npm:6.1.3" + dependencies: + "@adobe/css-tools": ^4.3.0 + "@babel/runtime": ^7.9.2 + aria-query: ^5.0.0 + chalk: ^3.0.0 + css.escape: ^1.5.1 + dom-accessibility-api: ^0.5.6 + lodash: ^4.17.15 + redent: ^3.0.0 + peerDependencies: + "@jest/globals": ">= 28" + "@types/jest": ">= 28" + jest: ">= 28" + vitest: ">= 0.32" + peerDependenciesMeta: + "@jest/globals": + optional: true + "@types/jest": + optional: true + jest: + optional: true + vitest: + optional: true + checksum: 544e01939d3c14a3d44ae2e2bb9fe2a0cb5a9e4992ca2728f41188fb9fb2d56e25f1a2e1c12000be2a94d8da36cb220b24020e1b5c5c4c4bede9058a0d80583d + languageName: node + linkType: hard + "@testing-library/react@npm:^11.2.2": version: 11.2.7 resolution: "@testing-library/react@npm:11.2.7"