test: add testing-library user event , utils and update path resolver

This commit is contained in:
Diana Olarte
2025-09-24 20:56:34 +10:00
committed by Adolfo R. Brandes
parent f742571fd1
commit 34519a3d08
4 changed files with 54 additions and 9 deletions

View File

@@ -6,6 +6,9 @@ module.exports = createConfig('jest', {
setupFilesAfterEnv: [
'<rootDir>/src/setupTest.jsx',
],
moduleNameMapper: {
'^@src/(.*)$': '<rootDir>/src/$1',
},
coveragePathIgnorePatterns: [
'src/setupTest.jsx',
'src/i18n',

15
package-lock.json generated
View File

@@ -27,6 +27,7 @@
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/react": "^18",
"@types/react-dom": "^18"
}
@@ -8002,6 +8003,20 @@
}
}
},
"node_modules/@testing-library/user-event": {
"version": "14.6.1",
"resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.6.1.tgz",
"integrity": "sha512-vq7fv0rnt+QTXgPxr5Hjc210p6YKq2kmdziLgnsZGgLJ9e6VAShx1pACLuRjd/AS/sr7phAR58OIIpf0LlmQNw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12",
"npm": ">=6"
},
"peerDependencies": {
"@testing-library/dom": ">=7.21.4"
}
},
"node_modules/@tokens-studio/sd-transforms": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@tokens-studio/sd-transforms/-/sd-transforms-1.3.0.tgz",

View File

@@ -37,10 +37,10 @@
},
"dependencies": {
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
"@openedx/frontend-plugin-framework": "^1.7.0",
"@edx/frontend-component-header": "^6.4.0",
"@edx/frontend-platform": "^8.3.0",
"@edx/openedx-atlas": "^0.7.0",
"@openedx/frontend-plugin-framework": "^1.7.0",
"@openedx/paragon": "^23.4.5",
"@tanstack/react-query": "5.89.0",
"react": "^18.3.1",
@@ -49,12 +49,13 @@
},
"devDependencies": {
"@edx/browserslist-config": "^1.1.1",
"@openedx/frontend-build": "14.6.2",
"@edx/typescript-config": "1.1.0",
"@types/react": "^18",
"@types/react-dom": "^18",
"@openedx/frontend-build": "14.6.2",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0"
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/react": "^18",
"@types/react-dom": "^18"
}
}

View File

@@ -1,10 +1,36 @@
/* eslint-disable import/no-extraneous-dependencies */
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { AppProvider } from '@edx/frontend-platform/react';
import { BrowserRouter } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
const mockAppContext = {
authenticatedUser: {
username: 'testuser',
email: 'testuser@example.com',
},
config: {
...process.env,
},
};
export const renderWrapper = (children) => render(
<AppProvider>
{children}
</AppProvider>,
<BrowserRouter>
<AppContext.Provider value={mockAppContext}>
<IntlProvider locale="en">
{children}
</IntlProvider>
</AppContext.Provider>
</BrowserRouter>,
);
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
global.ResizeObserver = ResizeObserver;