forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtestSetupFile.js
More file actions
109 lines (100 loc) · 3.68 KB
/
testSetupFile.js
File metadata and controls
109 lines (100 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import "@testing-library/jest-dom";
import { TextEncoder, TextDecoder } from "util";
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// Suppress console.error noise from known React 16 + MUI v6 incompatibilities:
// 1. DOM nesting: AccordionSummary renders as <button> and contains IconButton
// (also <button>). This is a structural MUI pattern constraint; browsers are
// lenient but React 16/jsdom reports it. No test assertions depend on it.
// 2. act() batching: async Formik setFieldValue calls (after awaited dialog
// promises or direct reorder callbacks) fire outside act()'s flush window in
// React 16. Removed in React 17 via automatic batching; tests still pass.
const originalError = console.error.bind(console);
console.error = (...args) => {
const msg = typeof args[0] === "string" ? args[0] : "";
if (
msg.includes("cannot appear as a descendant of") ||
msg.includes("was not wrapped in act(")
) {
return;
}
originalError(...args);
};
// Suppress console.warn noise from third-party packages that use deprecated
// React 16 lifecycle names (componentWillMount / componentWillReceiveProps).
// react-router-dom v5 and connected-react-router trigger these on every render.
// This filter is scoped to known third-party deprecations so real warnings
// from application code still surface.
const originalWarn = console.warn.bind(console);
console.warn = (...args) => {
const msg = typeof args[0] === "string" ? args[0] : "";
if (
msg.includes("componentWillMount has been renamed") ||
msg.includes("componentWillReceiveProps has been renamed") ||
msg.includes("componentWillUpdate has been renamed") ||
msg.includes("React.createFactory() is deprecated")
) {
return;
}
originalWarn(...args);
};
// @react-pdf/renderer >= 4 pulls ESM-only yoga-layout, which Jest in this
// project cannot parse (import.meta). Tests do not validate PDF rendering
// internals, so we provide a lightweight mock to keep test imports stable.
jest.mock("@react-pdf/renderer", () => {
const React = require("react");
const passthrough = ({ children }) =>
React.createElement("div", null, children);
return {
__esModule: true,
Document: passthrough,
Page: passthrough,
Text: passthrough,
View: passthrough,
Image: passthrough,
PDFViewer: passthrough,
PDFDownloadLink: ({ children }) =>
typeof children === "function"
? children({ blob: null, url: null, loading: false, error: null })
: children,
BlobProvider: ({ children }) =>
typeof children === "function"
? children({ blob: null, url: null, loading: false, error: null })
: children,
StyleSheet: { create: (styles) => styles },
Font: { register: jest.fn() },
pdf: jest.fn(() => ({
updateContainer: jest.fn(),
toBlob: () => Promise.resolve(null),
toString: () => Promise.resolve(""),
toBuffer: () => Promise.resolve(Buffer.from(""))
}))
};
});
// MUI v6 expects non-pooled synthetic events (React 17+). In this repo we
// still run React 16 in tests, so we mock the CJS lazy ripple internals used by
// ButtonBase to avoid pending ripple promises and event reuse warnings.
jest.mock("@mui/material/node/useLazyRipple", () => {
const createRipple = () => ({
start: jest.fn(),
stop: jest.fn(),
pulsate: jest.fn()
});
class LazyRipple {
static use() {
return {
ref: { current: createRipple() },
shouldMount: false,
start: jest.fn(),
stop: jest.fn(),
pulsate: jest.fn()
};
}
}
const useLazyRipple = () => LazyRipple.use();
return {
__esModule: true,
default: useLazyRipple,
LazyRipple
};
});