@@ -124,6 +124,7 @@ export interface DetectionHelpers {
124
124
}
125
125
126
126
const USER_EVENT_PACKAGE = '@testing-library/user-event' ;
127
+ const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils' ;
127
128
const FIRE_EVENT_NAME = 'fireEvent' ;
128
129
const USER_EVENT_NAME = 'userEvent' ;
129
130
const RENDER_NAME = 'render' ;
@@ -157,6 +158,7 @@ export function detectTestingLibraryUtils<
157
158
let importedTestingLibraryNode : ImportModuleNode | null = null ;
158
159
let importedCustomModuleNode : ImportModuleNode | null = null ;
159
160
let importedUserEventLibraryNode : ImportModuleNode | null = null ;
161
+ let importedReactDomTestUtilsNode : ImportModuleNode | null = null ;
160
162
161
163
// Init options based on shared ESLint settings
162
164
const customModuleSetting =
@@ -889,11 +891,14 @@ export function detectTestingLibraryUtils<
889
891
* parts of the file.
890
892
*/
891
893
ImportDeclaration ( node : TSESTree . ImportDeclaration ) {
894
+ if ( typeof node . source . value !== 'string' ) {
895
+ return ;
896
+ }
892
897
// check only if testing library import not found yet so we avoid
893
898
// to override importedTestingLibraryNode after it's found
894
899
if (
895
900
! importedTestingLibraryNode &&
896
- / t e s t i n g - l i b r a r y / g. test ( node . source . value as string )
901
+ / t e s t i n g - l i b r a r y / g. test ( node . source . value )
897
902
) {
898
903
importedTestingLibraryNode = node ;
899
904
}
@@ -904,7 +909,7 @@ export function detectTestingLibraryUtils<
904
909
if (
905
910
customModule &&
906
911
! importedCustomModuleNode &&
907
- String ( node . source . value ) . endsWith ( customModule )
912
+ node . source . value . endsWith ( customModule )
908
913
) {
909
914
importedCustomModuleNode = node ;
910
915
}
@@ -913,10 +918,19 @@ export function detectTestingLibraryUtils<
913
918
// to override importedUserEventLibraryNode after it's found
914
919
if (
915
920
! importedUserEventLibraryNode &&
916
- String ( node . source . value ) === USER_EVENT_PACKAGE
921
+ node . source . value === USER_EVENT_PACKAGE
917
922
) {
918
923
importedUserEventLibraryNode = node ;
919
924
}
925
+
926
+ // check only if react-dom/test-utils import not found yet so we avoid
927
+ // to override importedReactDomTestUtilsNode after it's found
928
+ if (
929
+ ! importedUserEventLibraryNode &&
930
+ node . source . value === REACT_DOM_TEST_UTILS_PACKAGE
931
+ ) {
932
+ importedReactDomTestUtilsNode = node ;
933
+ }
920
934
} ,
921
935
922
936
// Check if Testing Library related modules are loaded with required.
0 commit comments