For testcafe-testing-library, I'd like to support a use case for when navigation occurs (clicking a link, reloading, etc). In order to do this, I need to inject dom-testing-library into the DOM on each page-load
I propose adding an event subscription which I can subscribe to in a test or hook.
await t
.on("pageload", () => addTestcafeTestingLibrary(t))
.click(getByText("link to other page")
.click(getByText("link to yet another page")
.expect(getByText("element on other page").exists)
.ok();
I have a work around, but it requires manually injecting after the link click, it works, but it's toothy and cumbersome. For example, in the example above, i have to do this:
await addTestCafeTestingLibrary(t);
await t.click(getByText("link to other page"));
await addTestcafeTestingLibrary(t);
await t.click(getByText("link to yet another page"));
await addTestcafeTestingLibrary(t);
await t
.expect(getByText("element on other page").exists)
.ok();
quite verbose as you can see. hence the desire to have an event I can subscribe to for whenever a page load occurs....
Thank you for your proposal. We'll consider its implementation with the team if the idea becomes popular.
Hi @AlexKamaev Thank you. Are there any work arounds you know of that I can use in the meantime to allow me to inject scripts into the page whenever a navigation event occurs?
You can try to wrap the click action and use it for clicks that lead to the page reload. For example:
const clickThatLeadsToReload = async (t, selector) => {
await t.click(selector);
await addTestcafeTestingLibrary(t);
};
await clickThatLeadsToReload(t, getByText("link to other page"));
@alexkamaev I'd be happy to submit a PR of you could point me in the right direction... Like where does testcafe interact with hammer head?
found a solution using the testRun class.
@benmonro Can https://testing-library.com/docs/testcafe-testing-library/intro#known-issues be removed since it looks like you fixed this in https://github.com/testing-library/testcafe-testing-library/commit/5998cfd7671ac0643bc351fc74cceb4a939c06d0 ?
Ah yes. Nice catch. Thanks
@benmonro No, thank _you_. Really excited to use these two tools together. 🙇♂️
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.