Skip to content

Commit 4254547

Browse files
committed
fix: patch testing-library code to work in component tests
1 parent 0730f2e commit 4254547

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ const DOM_TESTING_LIBRARY_UMD_PATH = path.join(
4040
"dist/@testing-library/dom.umd.js",
4141
);
4242

43-
const DOM_TESTING_LIBRARY_UMD = fs.readFileSync(DOM_TESTING_LIBRARY_UMD_PATH).toString().replace("define.amd", "false");
43+
const DOM_TESTING_LIBRARY_UMD = fs
44+
.readFileSync(DOM_TESTING_LIBRARY_UMD_PATH)
45+
.toString()
46+
.replace("define.amd", "false")
47+
// exports and module are defined in component tests. Without this patch, testing-library won't init
48+
.replace("typeof exports === 'object' && typeof module !== 'undefined'", "false");
4449

4550
let _config: Partial<Config>;
4651

@@ -90,7 +95,7 @@ async function injectDOMTestingLibrary(container: WebdriverIO.Element) {
9095
);
9196
}
9297
} else {
93-
eval(library);
98+
window.eval(library);
9499
}
95100
}, DOM_TESTING_LIBRARY_UMD);
96101
}

0 commit comments

Comments
 (0)