Jest-puppeteer: Jest's native expect functions are broken by puppeteer-expect

Created on 20 Mar 2018  路  8Comments  路  Source: smooth-code/jest-puppeteer

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);

Most helpful comment

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')

All 8 comments

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)

@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

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

I'm using [email protected] 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

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?

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.

@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');

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')

Was this page helpful?
0 / 5 - 0 ratings