expect-puppeteer
Advanced tools
Comparing version 10.1.2 to 10.1.3
@@ -55,3 +55,3 @@ import { Page, Frame, ElementHandle, FrameWaitForFunctionOptions, ClickOptions, Dialog } from 'puppeteer'; | ||
type Wrapper<T> = T extends (page: Intersection<PuppeteerInstance>, ...args: infer A) => infer R ? (...args: A) => R : never; | ||
type PuppeteerMatchers<T> = T extends PuppeteerInstance ? { | ||
type InstanceMatchers<T> = T extends PuppeteerInstance ? { | ||
toClick: Wrapper<typeof toClick>; | ||
@@ -69,11 +69,11 @@ toFill: Wrapper<typeof toFill>; | ||
} : never; | ||
interface PageMatchers extends PuppeteerMatchers<Page> { | ||
interface PageMatchers extends InstanceMatchers<Page> { | ||
toDisplayDialog: Wrapper<typeof toDisplayDialog>; | ||
not: PuppeteerMatchers<Page>[`not`] & {}; | ||
not: InstanceMatchers<Page>[`not`] & {}; | ||
} | ||
interface FrameMatchers extends PuppeteerMatchers<Frame> { | ||
not: PuppeteerMatchers<Frame>[`not`] & {}; | ||
interface FrameMatchers extends InstanceMatchers<Frame> { | ||
not: InstanceMatchers<Frame>[`not`] & {}; | ||
} | ||
interface ElementHandleMatchers extends PuppeteerMatchers<ElementHandle<Element>> { | ||
not: PuppeteerMatchers<ElementHandle<Element>>[`not`] & {}; | ||
interface ElementHandleMatchers extends InstanceMatchers<ElementHandle<Element>> { | ||
not: InstanceMatchers<ElementHandle<Element>>[`not`] & {}; | ||
} | ||
@@ -84,22 +84,28 @@ type PMatchersPerType<T> = T extends Page ? PageMatchers : T extends Frame ? FrameMatchers : T extends ElementHandle<Element> ? ElementHandleMatchers : never; | ||
} | ||
interface PuppeteerMatchers<T> { | ||
toClick: T extends PuppeteerInstance ? Wrapper<typeof toClick> : never; | ||
toFill: T extends PuppeteerInstance ? Wrapper<typeof toFill> : never; | ||
toFillForm: T extends PuppeteerInstance ? Wrapper<typeof toFillForm> : never; | ||
toMatchTextContent: T extends PuppeteerInstance ? Wrapper<typeof toMatchTextContent> : never; | ||
toMatchElement: T extends PuppeteerInstance ? Wrapper<typeof toMatchElement> : never; | ||
toSelect: T extends PuppeteerInstance ? Wrapper<typeof toSelect> : never; | ||
toUploadFile: T extends PuppeteerInstance ? Wrapper<typeof toUploadFile> : never; | ||
toDisplayDialog: T extends Page ? Wrapper<typeof toDisplayDialog> : never; | ||
not: { | ||
toMatchTextContent: T extends PuppeteerInstance ? Wrapper<typeof notToMatchTextContent> : never; | ||
toMatchElement: T extends PuppeteerInstance ? Wrapper<typeof notToMatchElement> : never; | ||
}; | ||
} | ||
declare global { | ||
namespace jest { | ||
interface Matchers<R, T> { | ||
toClick: T extends PuppeteerInstance ? Wrapper<typeof toClick> : never; | ||
toFill: T extends PuppeteerInstance ? Wrapper<typeof toFill> : never; | ||
toFillForm: T extends PuppeteerInstance ? Wrapper<typeof toFillForm> : never; | ||
toMatchTextContent: T extends PuppeteerInstance ? Wrapper<typeof toMatchTextContent> : never; | ||
toMatchElement: T extends PuppeteerInstance ? Wrapper<typeof toMatchElement> : never; | ||
toSelect: T extends PuppeteerInstance ? Wrapper<typeof toSelect> : never; | ||
toUploadFile: T extends PuppeteerInstance ? Wrapper<typeof toUploadFile> : never; | ||
toDisplayDialog: T extends Page ? Wrapper<typeof toDisplayDialog> : never; | ||
not: { | ||
toMatchTextContent: T extends PuppeteerInstance ? Wrapper<typeof notToMatchTextContent> : never; | ||
toMatchElement: T extends PuppeteerInstance ? Wrapper<typeof notToMatchElement> : never; | ||
}; | ||
interface Matchers<R, T> extends PuppeteerMatchers<T> { | ||
} | ||
} | ||
} | ||
declare module "@jest/expect" { | ||
interface Matchers<R, T> extends PuppeteerMatchers<T> { | ||
} | ||
} | ||
declare const expectPuppeteer: PuppeteerExpect & JestExpect; | ||
export { type PuppeteerExpect, expectPuppeteer as expect, getDefaultOptions, setDefaultOptions }; |
@@ -296,3 +296,3 @@ 'use strict'; | ||
async function toClick(instance, selector, options = {}) { | ||
const { delay, button, clickCount, offset, ...otherOptions } = options; | ||
const { delay, button, count, offset, ...otherOptions } = options; | ||
const element = await toMatchElement(instance, selector, otherOptions); | ||
@@ -302,3 +302,3 @@ await element.click({ | ||
button, | ||
clickCount, | ||
count, | ||
offset | ||
@@ -417,3 +417,3 @@ }); | ||
const wrapMatcher = (matcher, instance)=>async function throwingMatcher(...args) { | ||
// ??? | ||
// update the assertions counter | ||
jestExpect.getState().assertionCalls += 1; | ||
@@ -440,3 +440,3 @@ try { | ||
]; | ||
if (!isPage && !isFrame && !isHandle) throw new Error(`${instance} is not supported`); | ||
if (!isPage && !isFrame && !isHandle) throw new Error(`${String(instance?.constructor?.name ?? `current instance`)} is not supported`); | ||
// retrieve matchers | ||
@@ -443,0 +443,0 @@ const expectation = { |
{ | ||
"name": "expect-puppeteer", | ||
"description": "Assertion toolkit for Puppeteer.", | ||
"version": "10.1.2", | ||
"version": "10.1.3", | ||
"type": "commonjs", | ||
@@ -53,3 +53,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "6a91899dd6257c83a243d9d38eb25b0397fb0fd0" | ||
"gitHead": "9b9e77cd0a5cc942cd9281374d498676eb200ccf" | ||
} |
@@ -27,3 +27,3 @@ # expect-puppeteer | ||
[Puppeteer API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md) is great, but it is low level and not designed for integration testing. | ||
[Puppeteer API](https://pptr.dev/api) is great, but it is low level and not designed for integration testing. | ||
@@ -85,7 +85,7 @@ This API is designed for integration testing: | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to click on. | ||
- `options` <[Object]> Optional parameters | ||
- `button` <"left"|"right"|"middle"> Defaults to `left`. | ||
- `clickCount` <[number]> defaults to 1. See [UIEvent.detail]. | ||
- `count` <[number]> defaults to 1. See [UIEvent.detail]. | ||
- `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. | ||
@@ -116,4 +116,4 @@ - `text` <[string]|[RegExp]> A text or a RegExp to match in element `textContent`. | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to match field | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to match field | ||
- `value` <[string]> Value to fill | ||
@@ -131,4 +131,4 @@ - `options` <[Object]> Optional parameters | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to match form | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to match form | ||
- `values` <[Object]> Values to fill | ||
@@ -149,3 +149,3 @@ - `options` <[Object]> Optional parameters | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `matcher` <[string]|[RegExp]> A text or a RegExp to match in page | ||
@@ -170,4 +170,4 @@ - `options` <[Object]> Optional parameters | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to match element | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to match element | ||
- `options` <[Object]> Optional parameters | ||
@@ -192,4 +192,4 @@ - `polling` <[string]|[number]> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values: | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to match select [element] | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to match select [element] | ||
- `valueOrText` <[string]> Value or text matching option | ||
@@ -205,5 +205,5 @@ | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to match input [element] | ||
- `filePath` <[string]> A file path | ||
- `instance` <[Page]|[Frame]|[ElementHandle]> Context | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to match input [element] | ||
- `filePath` <[string]|[Array]<[string]>> A file path or array of file paths | ||
@@ -219,3 +219,3 @@ ```js | ||
### <a name="MatchSelector"></a>{type: [string], value: [string]} | ||
### <a name="MatchSelector"></a>Match Selector | ||
@@ -254,4 +254,5 @@ An object used as parameter in order to select an element. | ||
[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector" | ||
[page]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page "Page" | ||
[elementhandle]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-elementhandle "ElementHandle" | ||
[page]: https://pptr.dev/api/puppeteer.page "Page" | ||
[frame]: https://pptr.dev/api/puppeteer.frame "Frame" | ||
[elementhandle]: https://pptr.dev/api/puppeteer.elementhandle/ "ElementHandle" | ||
[uievent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail |
36987
562
249