Skip to content

Commit 37e3271

Browse files
authored
fix: fix types resolution for expect-puppeteer (#599)
1 parent ced391e commit 37e3271

23 files changed

+2804
-1041
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async function getConfig() {
131131
module.exports = getConfig();
132132
```
133133

134-
## Recipes
134+
## <a name="recipes"></a>Recipes
135135

136136
### Enhance testing with `expect-puppeteer` lib
137137

@@ -490,6 +490,30 @@ beforeEach(async () => {
490490

491491
TypeScript is natively supported from v8.0.0, for previous versions, you have to use [community-provided types](https://github.com/DefinitelyTyped/DefinitelyTyped).
492492

493+
Note though that it still requires installation of the [type definitions for jest](https://www.npmjs.com/package/@types/jest) :
494+
495+
```bash
496+
npm install --save-dev @types/jest
497+
```
498+
499+
Once setup, import the modules to enable types resolution for the exposed globals, then write your test logic [the same way you would in Javascript](#recipes).
500+
501+
```ts
502+
// import globals
503+
import "jest-puppeteer";
504+
import "expect-puppeteer";
505+
506+
describe("Google", (): void => {
507+
beforeAll(async (): Promise<void> => {
508+
await page.goto("https://google.com");
509+
});
510+
511+
it('should display "google" text on page', async (): Promise<void> => {
512+
await expect(page).toMatchTextContent("google");
513+
});
514+
});
515+
```
516+
493517
### CI Timeout
494518

495519
Most Continuous Integration (CI) platforms restrict the number of threads you can use. If you run multiple test suites, the tests may timeout due to Jest attempting to run Puppeteer in parallel, and the CI platform being unable to process all parallel jobs in time.

package-lock.json

Lines changed: 2396 additions & 783 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"packages/*"
55
],
66
"scripts": {
7+
"typecheck": "npx tsc && echo 'type checking was successful'",
78
"build": "cross-env NODE_ENV=production lerna run build",
89
"dev": "lerna watch -- lerna run build --scope=\\$LERNA_PACKAGE_NAME",
910
"format": "prettier --write .",

packages/expect-puppeteer/src/index.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getDefaultOptions, setDefaultOptions } from ".";
1+
import { getDefaultOptions, setDefaultOptions } from "expect-puppeteer";
2+
3+
// import globals
4+
import "jest-puppeteer";
5+
import "expect-puppeteer";
26

37
expect.addSnapshotSerializer({
48
print: () => "hello",

0 commit comments

Comments
 (0)