Skip to content

Commit 99d542e

Browse files
committed
fix: support original Jest matchers
Fixes #17
1 parent 36e3fd9 commit 99d542e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/expect-puppeteer/src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,18 @@ if (typeof global.expect !== 'undefined') {
8888
const originalExpect = global.expect
8989
global.expect = (actual, ...args) => {
9090
const type = getPuppeteerType(actual)
91-
if (type) return expectPuppeteer(actual)
91+
if (type) {
92+
const matchers = expectPuppeteer(actual)
93+
const jestMatchers = originalExpect(actual, ...args)
94+
return {
95+
...jestMatchers,
96+
...matchers,
97+
not: {
98+
...jestMatchers.not,
99+
...matchers.not,
100+
},
101+
}
102+
}
92103
return originalExpect(actual, ...args)
93104
}
94105
Object.keys(originalExpect).forEach(prop => {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe('expect-puppeteer', () => {
2+
beforeEach(async () => {
3+
await page.goto('http://localhost:4444')
4+
})
5+
6+
it('should work with original Jest matchers', async () => {
7+
expect(page).toBeDefined()
8+
expect(page).not.toBe(null)
9+
10+
const main = await page.$('main')
11+
expect(main).toBeDefined()
12+
expect(main).not.toBe(null)
13+
})
14+
})

0 commit comments

Comments
 (0)