Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
470 changes: 352 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@
"@storybook/test": "8.4.7",
"@storybook/theming": "8.4.7",
"@storybook/types": "8.4.7",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/jest-dom": "6.7.0",
"@testing-library/react": "14.3.0",
"@testing-library/react-native": "12.4.3",
"@testing-library/user-event": "14.4.3",
"@types/eslint": "8.56.9",
"@types/estree": "1.0.5",
"@types/istanbul-lib-report": "3.0.0",
"@types/jest": "30.0.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add this to the root of the monorepo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a dependency we previously inherited through the older version of @testing-library/jest-dom, but is no longer a dependency of the latest version. We rely on it so that we can have typed Jest globals without importing from the @jest/globals package. This changes it from an implicit dependency to an explicit dependency.

"@types/mime": "2.0.3",
"@types/node": "20.17.10",
"@types/npm-package-arg": "6.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/color-palette/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ describe( 'ColorPalette', () => {
const dropdownColorInput = screen.getByLabelText( 'Hex color' );

await waitFor( () =>
// @ts-expect-error - FIXME: `toBePositionedPopover` should probably be in its own package.
expect( dropdownColorInput ).toBePositionedPopover()
);
} );
Expand Down
4 changes: 1 addition & 3 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"compilerOptions": {
"types": [
"gutenberg-env",
"gutenberg-test-env",
"jest",
"@testing-library/jest-dom"
"gutenberg-test-env"
]
},
"references": [
Expand Down
4 changes: 1 addition & 3 deletions packages/dataviews/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"compilerOptions": {
"types": [
"gutenberg-env",
"gutenberg-test-env",
"jest",
"@testing-library/jest-dom"
"gutenberg-test-env"
]
},
"references": [
Expand Down
46 changes: 0 additions & 46 deletions packages/jest-console/src/declarations.d.ts

This file was deleted.

7 changes: 6 additions & 1 deletion packages/jest-console/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
* Internal dependencies
*/
import './matchers';
import './types';
import supportedMatchers from './supported-matchers';
import type { ExtendedMock } from './types';

type ValueOf< T > = T[ keyof T ];

/**
* Sets spy on the console object's method to make it possible to fail test when method called without assertion.
*
* @param args
*/
const setConsoleMethodSpy = ( args: [ string, string ] ) => {
const setConsoleMethodSpy = (
args: [ string, ValueOf< typeof supportedMatchers > ]
) => {
const [ methodName, matcherName ] = args;
const spy = jest
.spyOn( console, methodName as 'error' | 'info' | 'log' | 'warn' )
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-console/src/supported-matchers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const supportedMatchers: Record< string, string > = {
const supportedMatchers = {
error: 'toHaveErrored',
info: 'toHaveInformed',
log: 'toHaveLogged',
warn: 'toHaveWarned',
};
} as const;

export default supportedMatchers;
49 changes: 49 additions & 0 deletions packages/jest-console/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,55 @@
*/
import type { Mock } from 'jest-mock';

// Definitions originally written by Damien Sorel <https://github.com/mistic100> under MIT license.
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f0b72c12f6b561e4342dc8a1cf87432d2ad40ae7/types/wordpress__jest-console/index.d.ts

declare global {
namespace jest {
interface Matchers< R > {
/**
* Ensure that `console.error` function was called.
*/
toHaveErrored: () => R;

/**
* Ensure that `console.error` function was called with specific arguments.
*/
toHaveErroredWith: ( ...args: unknown[] ) => R;

/**
* Ensure that `console.info` function was called.
*/
toHaveInformed: () => R;

/**
* Ensure that `console.info` function was called with specific arguments.
*/
toHaveInformedWith: ( ...args: unknown[] ) => R;

/**
* Ensure that `console.log` function was called.
*/
toHaveLogged: () => R;

/**
* Ensure that `console.log` function was called with specific arguments.
*/
toHaveLoggedWith: ( ...args: unknown[] ) => R;

/**
* Ensure that `console.warn` function was called.
*/
toHaveWarned: () => R;

/**
* Ensure that `console.warn` function was called with specific arguments.
*/
toHaveWarnedWith: ( ...args: unknown[] ) => R;
}
}
}

/**
* Interface for the extended Jest Mock that includes the assertionsNumber property
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-console/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"files": [ "src/declarations.d.ts" ],
"compilerOptions": {
"types": [ "jest", "@testing-library/jest-dom" ]
"types": [ "gutenberg-test-env" ]
}
}
6 changes: 6 additions & 0 deletions typings/gutenberg-test-env/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import '@types/node';
import '@types/jest';
import '@testing-library/jest-dom';
import 'snapshot-diff';
import '@wordpress/jest-console';

declare namespace jest {
interface Matchers< R > {
/**
Expand Down
Loading