Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["react", "jsx-a11y"],
"plugins": ["react", "jsx-a11y", "jest"],
"jsPlugins": [
"eslint-plugin-rsp-rules",
{
Expand Down Expand Up @@ -192,6 +192,7 @@
"rsp-rules/imports": ["error"],
"rsp-rules/use-layout-effect-rule": ["error"],
"rsp-rules/pure-render": ["error"],
"jest/no-alias-methods": "error",
"jsx-a11y/alt-text": "error",
"jsx-a11y/anchor-has-content": "error",
"jsx-a11y/anchor-is-valid": "error",
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module.exports = {

// Options that will be passed to the testEnvironment
testEnvironmentOptions: {
globalsCleanup: 'on',
customExportConditions: ['source']
},

Expand Down
5 changes: 5 additions & 0 deletions jest.ssr.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = {
// The test environment that will be used for testing
testEnvironment: 'jsdom',

// Match jest.config.js so the in-repo `"source"` export condition wins over `require`.
testEnvironmentOptions: {
customExportConditions: ['source']
},

setupFilesAfterEnv: ['<rootDir>scripts/setupTests.js'],

// The glob patterns Jest uses to detect test files
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
"@storybook/react": "^10.0.0",
"@storybook/test-runner": "^0.24.0",
"@swc/core": "^1.3.36",
"@swc/jest": "^0.2.36",
"@swc/jest": "^0.2.39",
"@tailwindcss/postcss": "^4.0.17",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^16.0.0",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "patch:@testing-library/user-event@npm%3A14.6.1#~/.yarn/patches/@testing-library-user-event-npm-14.6.1-5da7e1d4e2.patch",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand All @@ -151,6 +151,7 @@
"delta-e": "^0.0.8",
"diff": "^5.1.0",
"eslint-import-resolver-node": "^0.3.10",
"eslint-plugin-jest": "29.15.2",
"eslint-plugin-react-hooks": "^7.0.0",
"exceljs": "^4.4.0",
"fast-check": "^2.19.0",
Expand All @@ -160,15 +161,16 @@
"identity-obj-proxy": "^3.0.0",
"ignore-styles": "^5.0.1",
"is-mingw": "^2.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-junit": "^15.0.0",
"jest-matchmedia-mock": "^1.1.0",
"jest": "^30.0.0",
"jest-environment-jsdom": "^30.0.0",
"jest-junit": "^17.0.0",
"json5": "^2.2.3",
"lerna": "^3.13.2",
"lucide-react": "^0.517.0",
"md5": "^2.2.1",
"mdast-util-to-string": "^4.0.0",
"media-query-fns": "^2.1.2",
"mock-match-media": "^1.0.0",
"motion": "^12.23.6",
"npm-cli-login": "^1.0.0",
"oxfmt": "^0.48.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ describe('ActionGroup', function () {
let [button1, button2] = getAllByRole('radio');
await user.click(button1);
expect(button1).toHaveAttribute('disabled');
expect(onSelectionChange).toBeCalledTimes(0);
expect(onSelectionChange).toHaveBeenCalledTimes(0);
await user.click(button2);
expect(button2).not.toHaveAttribute('disabled');
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
});

it('ActionGroup handles selectedKeys (controlled)', async function () {
Expand All @@ -453,7 +453,7 @@ describe('ActionGroup', function () {
expect(button1).toHaveAttribute('aria-checked', 'true');
expect(button2).toHaveAttribute('aria-checked', 'false');
await user.click(button2);
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(button1).toHaveAttribute('aria-checked', 'true');
expect(button2).toHaveAttribute('aria-checked', 'false');
});
Expand All @@ -470,7 +470,7 @@ describe('ActionGroup', function () {
expect(button1).toHaveAttribute('aria-checked', 'true');
expect(button2).toHaveAttribute('aria-checked', 'false');
await user.click(button2);
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(button1).toHaveAttribute('aria-checked', 'false');
expect(button2).toHaveAttribute('aria-checked', 'true');
});
Expand All @@ -481,10 +481,10 @@ describe('ActionGroup', function () {

let [button1] = getAllByRole('radio');
await user.click(button1);
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(new Set(onSelectionChange.mock.calls[0][0])).toEqual(new Set(['1']));
await user.click(button1);
expect(onSelectionChange).toBeCalledTimes(2);
expect(onSelectionChange).toHaveBeenCalledTimes(2);
expect(new Set(onSelectionChange.mock.calls[1][0])).toEqual(new Set([]));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('SearchAutocomplete', function () {
});

it('renders with placeholder text and shows warning', function () {
let spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
using spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
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.

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.

?

let {getByPlaceholderText, getByRole} = renderSearchAutocomplete({
placeholder: 'Test placeholder'
});
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('SearchAutocomplete', function () {
});

let listbox = getByRole('listbox');
expect(onOpenChange).toBeCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledWith(true, 'focus');
await testSearchAutocompleteOpen(searchAutocomplete, listbox);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ describe('CheckboxGroup', () => {
'warns if %s is passed to an individual checkbox',
prop => {
let props = {[prop]: true};
let spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
using spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
render(
<Provider theme={theme}>
<CheckboxGroup label="Favorite Pet">
Expand Down
6 changes: 3 additions & 3 deletions packages/@adobe/react-spectrum/test/color/ColorField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('ColorField', function () {
});

it('should allow placeholder and show warning', function () {
let spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
using spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
let {getByPlaceholderText, getByRole} = renderComponent({placeholder: 'Enter a color'});
expect(getByRole('textbox')).toBe(getByPlaceholderText('Enter a color'));
expect(spyWarn).toHaveBeenCalledWith(
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('ColorField', function () {
let [value, setValue] = React.useState(parseColor('#7f0000'));
return (
<form>
<ColorField value={value} onChange={setValue} />
<ColorField value={value} onChange={setValue} aria-label="mandatory label" />
<input type="reset" data-testid="reset" />
</form>
);
Expand All @@ -419,7 +419,7 @@ describe('ColorField', function () {

return (
<form action={formAction}>
<ColorField defaultValue={value} />
<ColorField defaultValue={value} aria-label="mandatory label" />
<input type="submit" data-testid="submit" />
</form>
);
Expand Down
42 changes: 21 additions & 21 deletions packages/@adobe/react-spectrum/test/combobox/ComboBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ describe('ComboBox', function () {
});

it('renders with placeholder text and shows warning', function () {
let spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
using spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
let {getByPlaceholderText, getByRole} = renderComboBox({placeholder: 'Test placeholder'});

let searchAutocomplete = getByRole('combobox');
Expand Down Expand Up @@ -472,7 +472,7 @@ describe('ComboBox', function () {
await comboboxTester.open({triggerBehavior: 'focus'});

let listbox = comboboxTester.getListbox();
expect(onOpenChange).toBeCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledWith(true, 'focus');
await testComboBoxOpen(combobox, button, listbox);
});
Expand All @@ -486,7 +486,7 @@ describe('ComboBox', function () {
await comboboxTester.open({triggerBehavior: 'manual'});

let listbox = comboboxTester.getListbox();
expect(onOpenChange).toBeCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledTimes(1);
expect(onOpenChange).toHaveBeenCalledWith(true, 'focus');
await testComboBoxOpen(combobox, button, listbox);
});
Expand Down Expand Up @@ -1274,7 +1274,7 @@ describe('ComboBox', function () {
await user.keyboard('a');

expect(combobox.value).toBe('blah');
expect(onInputChange).toBeCalledTimes(1);
expect(onInputChange).toHaveBeenCalledTimes(1);
expect(onInputChange).toHaveBeenCalledWith('blaha');
});

Expand Down Expand Up @@ -1831,7 +1831,7 @@ describe('ComboBox', function () {
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledWith('1');
expect(document.activeElement).toBe(combobox);
expect(onBlur).not.toBeCalled();
expect(onBlur).not.toHaveBeenCalled();
});

it('tab and shift tab move focus away from the combobox and select the focused item', async function () {
Expand Down Expand Up @@ -2776,19 +2776,19 @@ describe('ComboBox', function () {

if (!Name.includes('value') && !Name.includes('all')) {
// Check that onInputChange is firing appropriately for the comboboxes w/o user defined onInputChange handlers
expect(onInputChange).toBeCalledTimes(3);
expect(onInputChange).toHaveBeenCalledTimes(3);
expect(onInputChange).toHaveBeenLastCalledWith('One');
}

if (Name === 'controlled value and open') {
// Checking special case, spy is chained with the onSelectionChangeHandler
expect(onSelectionChange).toBeCalledTimes(2);
expect(onSelectionChange).toHaveBeenCalledTimes(2);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}

if (!Name.includes('open') && !Name.includes('all')) {
// Check that onOpenChange is firing appropriately for the comboboxes w/o user defined onOpenChange handlers
expect(onOpenChange).toBeCalledTimes(4);
expect(onOpenChange).toHaveBeenCalledTimes(4);
expect(onOpenChange).toHaveBeenLastCalledWith(false, undefined);
}

Expand Down Expand Up @@ -2829,19 +2829,19 @@ describe('ComboBox', function () {

if (!Name.includes('value') && !Name.includes('all')) {
// Check that onInputChange is firing appropriately for the comboboxes w/o user defined onInputChange handlers
expect(onInputChange).toBeCalledTimes(3);
expect(onInputChange).toHaveBeenCalledTimes(3);
expect(onInputChange).toHaveBeenLastCalledWith('One');
}

if (Name === 'controlled value and open') {
// Checking special case, spy is chained with the onSelectionChangeHandler
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}

if (!Name.includes('open') && !Name.includes('all')) {
// Check that onOpenChange is firing appropriately for the comboboxes w/o user defined onOpenChange handlers
expect(onOpenChange).toBeCalledTimes(2);
expect(onOpenChange).toHaveBeenCalledTimes(2);
expect(onOpenChange).toHaveBeenLastCalledWith(false, undefined);
}

Expand Down Expand Up @@ -2897,19 +2897,19 @@ describe('ComboBox', function () {

if (!Name.includes('value') && !Name.includes('all')) {
// Check that onInputChange is firing appropriately for the comboboxes w/o user defined onInputChange handlers
expect(onInputChange).toBeCalledTimes(5);
expect(onInputChange).toHaveBeenCalledTimes(5);
expect(onInputChange).toHaveBeenLastCalledWith('One');
}

if (Name === 'controlled value and open') {
// Checking special case, spy is chained with the onSelectionChangeHandler
expect(onSelectionChange).toBeCalledTimes(2);
expect(onSelectionChange).toHaveBeenCalledTimes(2);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}

if (!Name.includes('open') && !Name.includes('all')) {
// Check that onOpenChange is firing appropriately for the comboboxes w/o user defined onOpenChange handlers
expect(onOpenChange).toBeCalledTimes(4);
expect(onOpenChange).toHaveBeenCalledTimes(4);
expect(onOpenChange).toHaveBeenLastCalledWith(false, undefined);
}
});
Expand Down Expand Up @@ -2946,19 +2946,19 @@ describe('ComboBox', function () {

if (!Name.includes('value') && !Name.includes('all')) {
// Check that onInputChange is firing appropriately for the comboboxes w/o user defined onInputChange handlers
expect(onInputChange).toBeCalledTimes(5);
expect(onInputChange).toHaveBeenCalledTimes(5);
expect(onInputChange).toHaveBeenLastCalledWith('');
}

if (Name === 'controlled value and open') {
// Checking special case, spy is chained with the onSelectionChangeHandler
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenLastCalledWith(null);
}

if (!Name.includes('open') && !Name.includes('all')) {
// Check that onOpenChange is firing appropriately for the comboboxes w/o user defined onOpenChange handlers
expect(onOpenChange).toBeCalledTimes(2);
expect(onOpenChange).toHaveBeenCalledTimes(2);
expect(onOpenChange).toHaveBeenLastCalledWith(false, undefined);
}
});
Expand Down Expand Up @@ -2993,7 +2993,7 @@ describe('ComboBox', function () {
(!Name.includes('key') && !Name.includes('all')) ||
Name === 'controlled value and open'
) {
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}
expect(queryByRole('listbox')).toBeNull();
Expand All @@ -3009,7 +3009,7 @@ describe('ComboBox', function () {
if (Name === 'controlled value and open') {
// Checking special case, spy is chained with the onSelectionChangeHandler
// onSelectionChange is called on blur due to commitSelection (so that input value resets)
expect(onSelectionChange).toBeCalledTimes(2);
expect(onSelectionChange).toHaveBeenCalledTimes(2);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}

Expand All @@ -3030,7 +3030,7 @@ describe('ComboBox', function () {
expect(queryByRole('listbox')).toBeNull();

if (!Name.includes('value') && !Name.includes('all')) {
expect(onInputChange).toBeCalledTimes(5);
expect(onInputChange).toHaveBeenCalledTimes(5);
expect(onInputChange).toHaveBeenLastCalledWith('New Text');
}
});
Expand Down Expand Up @@ -3063,7 +3063,7 @@ describe('ComboBox', function () {
(!Name.includes('key') && !Name.includes('all')) ||
Name === 'controlled value and open'
) {
expect(onSelectionChange).toBeCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenLastCalledWith('1');
}
expect(queryByRole('listbox')).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ describe('DialogTrigger', function () {
});

it('should warn when unmounting a dialog trigger while a modal is open', async function () {
let warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
using warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
let {getByRole, queryByRole} = render(
<Provider theme={theme}>
<MenuTrigger>
Expand Down
2 changes: 1 addition & 1 deletion packages/@adobe/react-spectrum/test/image/Image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Image', () => {
);
fireEvent.error(screen.getByAltText('Sky and roof'));

expect(mockOnErrorCallback).toBeCalled();
expect(mockOnErrorCallback).toHaveBeenCalled();
});

describe('crossorigin attribute', () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/@adobe/react-spectrum/test/list/ListView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ describe('ListView', function () {
describe('selectionStyle highlight', function () {
installPointerEvent();
it('should toggle items in selection highlight with meta-click on Mac', async function () {
let uaMock = jest.spyOn(navigator, 'platform', 'get').mockImplementation(() => 'Mac');
using uaMock = jest.spyOn(navigator, 'platform', 'get').mockImplementation(() => 'Mac');
let tree = renderSelectionList({
onSelectionChange,
selectionMode: 'multiple',
Expand Down Expand Up @@ -1143,7 +1143,9 @@ describe('ListView', function () {
});

it('should allow multiple items to be selected in selection highlight with ctrl-click on Windows', async function () {
let uaMock = jest.spyOn(navigator, 'userAgent', 'get').mockImplementation(() => 'Windows');
using uaMock = jest
.spyOn(navigator, 'userAgent', 'get')
.mockImplementation(() => 'Windows');
let tree = renderSelectionList({
onSelectionChange,
selectionMode: 'multiple',
Expand Down Expand Up @@ -1178,7 +1180,9 @@ describe('ListView', function () {
});

it('should toggle items in selection highlight with ctrl-click on Windows', async function () {
let uaMock = jest.spyOn(navigator, 'userAgent', 'get').mockImplementation(() => 'Windows');
using uaMock = jest
.spyOn(navigator, 'userAgent', 'get')
.mockImplementation(() => 'Windows');
let tree = renderSelectionList({
onSelectionChange,
selectionMode: 'multiple',
Expand Down
Loading