Skip to content

Commit df6b39a

Browse files
committed
Fixes jsdom css parsing console errors when running tests
1 parent b89089c commit df6b39a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

jest.setup.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
import '@testing-library/jest-dom'
2-
import 'whatwg-fetch'
3-
import { server } from './__mocks__/server'
1+
import "@testing-library/jest-dom";
2+
import "whatwg-fetch";
3+
import { server } from "./__mocks__/server";
44

5-
beforeAll(() => server.listen());
6-
afterEach(() => server.resetHandlers())
7-
afterAll(() => server.close())
5+
beforeAll(() => {
6+
// Disable error logs from jsdom css parsing error
7+
/**
8+
* This is a workaround for the following issue:
9+
* NOTE: The error message "Error: Could not parse CSS stylesheet" is thrown by jsdom when it tries to parse a CSS file that contains an unsupported CSS feature.
10+
* TODO: Remove this workaround once the issue is fixed in jsdom.
11+
*/
12+
const originalConsoleError = console.error;
13+
const jsDomCssError = "Error: Could not parse CSS stylesheet";
14+
console.error = (...params) => {
15+
if (!params.find((p) => p.toString().includes(jsDomCssError))) {
16+
originalConsoleError(...params);
17+
}
18+
};
19+
20+
server.listen();
21+
});
22+
afterEach(() => server.resetHandlers());
23+
afterAll(() => server.close());

0 commit comments

Comments
 (0)