Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass arguments to browser in runJS #45

Merged
merged 4 commits into from
Mar 4, 2021

Conversation

calebeby
Copy link
Member

@calebeby calebeby commented Mar 2, 2021

Adds ability to pass variables to the browser in runJS:

import { withBrowser } from 'test-mule';
test(
  'runJS example with argument',
  withBrowser(async ({ utils, screen }) => {
    // element is an ElementHandle (pointer to an element in the browser)
    const element = await screen.getByText(/button/i);
    // we can pass element into runJS and the default exported function can access it as an Element
    await utils.runJS(
      `
        export default (element) => console.log(element);
      `,
      [element],
    );
  }),
);

Closes #28

In #28 I mentioned other syntax options for how to make this possible, open to feedback 👀

@emersonthis
Copy link
Contributor

@calebeby Should the test make an assertion to ensure that element is passed as we expect to the browser? As written, I think this test will fail with a ReferenceError if element isn't defined at all. But I think it would pass if it's anything else right? Even null or undefined? Is that worth checking for?

@calebeby
Copy link
Member Author

calebeby commented Mar 3, 2021

@emersonthis that was just an example I have from the changelog. I forgot to write an actual test, so I added one here: cd8d4d8

@calebeby calebeby merged commit 732fbff into main Mar 4, 2021
@calebeby calebeby deleted the allow-params-to-runjs branch March 4, 2021 19:51
@github-actions github-actions bot mentioned this pull request Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing variables into runJS
2 participants