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

Jest's native expect functions are broken by puppeteer-expect #17

Closed
Mstrodl opened this issue Mar 20, 2018 · 8 comments
Closed

Jest's native expect functions are broken by puppeteer-expect #17

Mstrodl opened this issue Mar 20, 2018 · 8 comments

Comments

@Mstrodl
Copy link

Mstrodl commented Mar 20, 2018

Hi, it looks like puppeteer-expect doesn't actually copy over the old jest expect's matchers. This causes a lot of problems like: TypeError: expect(...).not.toBe is not a function
Code:

const elementHandle = await page.$("input");
expect(elementHandle).not.toBe(null);
@Mstrodl Mstrodl changed the title Jest's expect is broken by puppeteer-expect Jest's native expect functions are broken by puppeteer-expect Mar 20, 2018
@gregberge
Copy link
Member

gregberge commented Mar 21, 2018

I expected this kind of problem. I think we can find a workaround for that. Actually the problem will only occur on ElementHandle and Page instances.

Two workarounds before the fix:

await expect(page).toMatchElement('input') // This will wait for element to be displayed

// or
const elementHandle = await page.$('input')
expect(elementHandle === null).toBe(false)

@gregberge gregberge added bug good first issue 🤙 Good for newcomers and removed good first issue 🤙 Good for newcomers help wanted labels Mar 21, 2018
@Mstrodl
Copy link
Author

Mstrodl commented Mar 21, 2018

@neoziro The issue is that I need to use the elements elsewhere in the test. So far the only workaround I've found uses another bug which is that promises don't get resolved by expect-puppeteer:

await expect(Promise.resolve(elementHandle)).resolves.not.toBe(null);

But again, that's a bit of a hack

@gregberge
Copy link
Member

OK, please be patient, I will work on this bug as soon as possible. It will be fixed before the end of week.

@gillesdemey
Copy link

I'm using puppeteer-expect@2.2.1 and I'm getting the following exception when running a standard assertion:

expect(response.status()).toBe(200)

The exception thrown:

Error: 200 is not supported

@parasvora
Copy link

parasvora commented Nov 15, 2018

I am facing this issue while trying to compare 2 strings.
expect('test').toContainEquals('Test');

It is throwing error:
test is not supported

@neoziro Any idea on this?

@gregberge
Copy link
Member

I think toContainEquals doesn't exist, either in Jest or in Puppeteer Expect.

You probably want toContainEqual and it only works with object. Nothing related with this project.

@parasvora
Copy link

@neoziro Sorry, it was a typing error, I did used
expect('test').toContainEqual('Test');

I am getting same error for below codes as well,
expect('test').toBe('Test');
expect('test').toMatch('Test');

@baurine
Copy link

baurine commented Mar 26, 2020

When I use expect-puppeteer with typescript by import expect from 'expect-puppeteer', the expect() method only accepts the Page or ElementHandle type parameter, other types will report error, so how I use puppeteer-expect and native expect both:

import ppExpect from 'expect-puppeteer'

...
    await ppExpect(page).toClick(...)
    expect('test').toBe('test')

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

No branches or pull requests

5 participants