Skip to content

Commit 914318d

Browse files
authored
Chart Library: Add initial testing infrastructure and PieChart component tests (#41148)
* Add dependencies for testing * set up config for tests * create testing file for pie chart with a few edge case tests * mock the ResizeObserver * changelog * simplify pie chart tests for initial setup * update dir from __tests__ to test * add back in src/* for typeRoots in tsconfig
1 parent 726137d commit 914318d

File tree

7 files changed

+166
-1
lines changed

7 files changed

+166
-1
lines changed

pnpm-lock.yaml

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Charts: adds dependencies and config for jest testing. Adds some initial tests to pie chart component
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="jest" />
2+
3+
declare global {
4+
const describe: jest.Describe;
5+
const test: jest.It;
6+
const expect: jest.Expect;
7+
const it: jest.It;
8+
const beforeAll: jest.Lifecycle;
9+
const afterAll: jest.Lifecycle;
10+
const beforeEach: jest.Lifecycle;
11+
const afterEach: jest.Lifecycle;
12+
}
13+
14+
export {};

projects/js-packages/charts/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@
9292
"tsconfig-paths-webpack-plugin": "4.2.0",
9393
"typescript": "5.7.2",
9494
"webpack": "^5.88.0",
95-
"webpack-cli": "^5.1.0"
95+
"webpack-cli": "^5.1.0",
96+
"@testing-library/react": "^14.0.0",
97+
"@testing-library/jest-dom": "^6.0.0",
98+
"@types/jest": "^29.0.0",
99+
"@types/testing-library__jest-dom": "^5.14.9",
100+
"@jest/globals": "^29.0.0",
101+
"babel-jest": "^29.7.0",
102+
"@automattic/jetpack-webpack-config": "workspace:*",
103+
"@wordpress/babel-plugin-import-jsx-pragma": "5.14.0",
104+
"@wordpress/element": "6.14.0",
105+
"@babel/plugin-transform-react-jsx": "7.25.9"
96106
},
97107
"peerDependencies": {
98108
"react": "^17.0.0 || ^18.0.0",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import { render } from '@testing-library/react';
6+
import { ThemeProvider } from '../../../providers/theme';
7+
import PieChart from '../pie-chart';
8+
9+
describe( 'PieChart', () => {
10+
it( 'renders', () => {
11+
const { container } = render(
12+
<ThemeProvider>
13+
<PieChart data={ [ { label: 'A', percentage: 100, value: 100 } ] } />
14+
</ThemeProvider>
15+
);
16+
expect( container ).toBeTruthy();
17+
} );
18+
} );

projects/js-packages/charts/tests/jest.config.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,16 @@ const baseConfig = require( 'jetpack-js-tools/jest/config.base.js' );
44
module.exports = {
55
...baseConfig,
66
rootDir: path.join( __dirname, '..' ),
7+
testEnvironment: 'jsdom',
8+
setupFilesAfterEnv: [
9+
...baseConfig.setupFilesAfterEnv,
10+
'@testing-library/jest-dom',
11+
'<rootDir>/tests/jest.setup.js',
12+
],
13+
transform: {
14+
...baseConfig.transform,
15+
'\\.[jt]sx?$': require( 'jetpack-js-tools/jest/babel-jest-config-factory.js' )(
16+
require.resolve
17+
),
18+
},
719
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class ResizeObserver {
2+
observe() {
3+
// do nothing
4+
}
5+
unobserve() {
6+
// do nothing
7+
}
8+
disconnect() {
9+
// do nothing
10+
}
11+
}
12+
13+
global.ResizeObserver = ResizeObserver;

0 commit comments

Comments
 (0)