2020 NodeList . prototype . includes = Array . prototype . includes ;
2121}
2222
23- // nwsapi 2.2.18 + jsdom: when antd v6 stylesheets contain `:has()` selectors,
24- // the resolver crashes inside `getComputedStyle` (called by Chakra's
25- // color-mode-provider on mount). Wrap `getComputedStyle` so a thrown selector
26- // returns an empty CSSStyleDeclaration instead of breaking the render.
23+ // Wrap `getComputedStyle` for two jsdom limitations:
24+ // 1. jsdom doesn't implement pseudo-element styles, so any `pseudoElt`
25+ // argument triggers a "Not implemented: window.computedStyle(elt,
26+ // pseudoElt)" log via its VirtualConsole. @rc-component's scrollbar
27+ // measurement passes one, so we drop it (pseudo-element styles aren't
28+ // available in jsdom anyway).
29+ // 2. nwsapi 2.2.18 crashes resolving antd v6's `:has()` selectors, so fall
30+ // back to an empty CSSStyleDeclaration when the underlying call throws.
2731if ( typeof window !== "undefined" ) {
2832 const originalGetComputedStyle = window . getComputedStyle . bind ( window ) ;
29- window . getComputedStyle = ( (
30- elt : Element ,
31- pseudoElt ?: string | null ,
32- ) : CSSStyleDeclaration => {
33+ window . getComputedStyle = ( ( elt : Element ) : CSSStyleDeclaration => {
3334 try {
34- return originalGetComputedStyle ( elt , pseudoElt ?? undefined ) ;
35+ return originalGetComputedStyle ( elt ) ;
3536 } catch {
3637 return {
3738 getPropertyValue : ( ) => "" ,
39+ length : 0 ,
3840 } as unknown as CSSStyleDeclaration ;
3941 }
4042 } ) as typeof window . getComputedStyle ;
@@ -60,3 +62,30 @@ if (typeof window !== "undefined") {
6062}
6163
6264installMessageChannelMock ( ) ;
65+
66+ // Filter console.error output for known noise that doesn't indicate a real bug.
67+ // React passes its warnings as a format string + substitutions (e.g.
68+ // `console.error("An update to %s inside a test...", "BaseSelect")`), so we
69+ // match against the unformatted first argument.
70+ // - antd List deprecation warning (no drop-in replacement exists yet)
71+ // - rc-trigger's "same shadow root" warning (jsdom doesn't implement shadow DOM)
72+ // - `NaN` height from antd-x Sender/Bubble.List measuring DOM that jsdom can't lay out
73+ // - React `act()` warnings from async updates in antd Select / next/dynamic /
74+ // rc-trigger that fire after the test assertion and can't be reasonably awaited
75+ const SUPPRESSED_CONSOLE_ERRORS = [
76+ "[antd: List] The `List` component is deprecated" ,
77+ "trigger element and popup element should in same shadow root" ,
78+ "`NaN` is an invalid value for the `%s` css style property" ,
79+ "An update to %s inside a test was not wrapped in act" ,
80+ ] ;
81+
82+ /* eslint-disable no-console */
83+ const originalConsoleError = console . error ;
84+ console . error = ( ...args : unknown [ ] ) => {
85+ const message = String ( args [ 0 ] ?? "" ) ;
86+ if ( SUPPRESSED_CONSOLE_ERRORS . some ( ( pattern ) => message . includes ( pattern ) ) ) {
87+ return ;
88+ }
89+ originalConsoleError ( ...args ) ;
90+ } ;
91+ /* eslint-enable no-console */
0 commit comments