Skip to content

Commit

Permalink
fix: support original Jest matchers
Browse files Browse the repository at this point in the history
Fixes #17
  • Loading branch information
gregberge committed Mar 25, 2018
1 parent 36e3fd9 commit 99d542e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/expect-puppeteer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,18 @@ if (typeof global.expect !== 'undefined') {
const originalExpect = global.expect
global.expect = (actual, ...args) => {
const type = getPuppeteerType(actual)
if (type) return expectPuppeteer(actual)
if (type) {
const matchers = expectPuppeteer(actual)
const jestMatchers = originalExpect(actual, ...args)
return {
...jestMatchers,
...matchers,
not: {
...jestMatchers.not,
...matchers.not,
},
}
}
return originalExpect(actual, ...args)
}
Object.keys(originalExpect).forEach(prop => {
Expand Down
14 changes: 14 additions & 0 deletions packages/expect-puppeteer/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('expect-puppeteer', () => {
beforeEach(async () => {
await page.goto('http://localhost:4444')
})

it('should work with original Jest matchers', async () => {
expect(page).toBeDefined()
expect(page).not.toBe(null)

const main = await page.$('main')
expect(main).toBeDefined()
expect(main).not.toBe(null)
})
})

0 comments on commit 99d542e

Please sign in to comment.