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

fix: handle toHaveText when receiving an array of elements #1571

Merged
merged 11 commits into from
Jun 13, 2024

Conversation

sangcnguyen
Copy link
Contributor

I'm trying to take a stab at this #1555. Could you help me review it?

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work , thanks so much!

🎉

@christian-bromann christian-bromann merged commit bedf208 into webdriverio:main Jun 13, 2024
6 checks passed
@wdio-bot
Copy link
Contributor

Hey sangcnguyen 👋

Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution. We've sent you an email with further instructions on how to claim your expenses from our development fund. Please make sure to check your spam folder as well. If you have any questions, feel free to reach out to us at [email protected] or in the contributing channel on Discord.

We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖

@lacell75
Copy link
Contributor

lacell75 commented Jun 14, 2024

Thanks for this PR , but toHaveText is not working with expect.arrayContaining.
For example, I wish to convert this deprecated API

await expect($('div').toHaveTextContaining(['text1', 'text2']);

with:

await expect($('div').toHaveText(expect.arrayContaining(['text1', 'text2'])            );

I have this error :

[chrome 125.0.6422.144 Windows 10 #0-0] Error: Expect $(`div`) to have text
[chrome 125.0.6422.144 Windows 10 #0-0] Error: Expect $(`div`) to have text
[chrome 125.0.6422.144 Windows 10 #0-0] Expected: ArrayContaining ["text1", "text2"]
[chrome 125.0.6422.144 Windows 10 #0-0] Received: "text1"

@christian-bromann
Copy link
Member

christian-bromann commented Jun 14, 2024

@lacell75 thanks for reporting. @sangcnguyen Let's make sure we can support both use cases.

@sangcnguyen
Copy link
Contributor Author

My hunch is does the code below work? I didn't know the use case of using 'expect.arrayContaining' before, so why do we need it?

await expect(await $('div')).toHaveText(['text1', 'text2']); 

@christian-bromann
Copy link
Member

@lacell75 mind providing more details? What do you expect to be asserted when calling

await expect($('div').toHaveText(expect.arrayContaining(['text1', 'text2']));

Do you expect that text1 and text2 are text in the div element? I also didn't know that await expect($('div').toHaveTextContaining(['text1', 'text2']); worked before 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants