Testing in Aurelia (2)

I recently added e2e testing with jest and puppeteer. The key was npm install jest-environment-puppeteer. Below are the basics.

Package.json

...

"testRegex": [
      "\\.spec\\.js$",
      "\\.e2e\\.js$"
    ],
    "setupFiles": [
      "<rootDir>/test/jest-pretest.js"
    ],
    "testEnvironment": "jest-environment-puppeteer",

...

    "preset": "jest-puppeteer",
    "globalSetup": "jest-environment-puppeteer/setup",
    "globalTeardown": "jest-environment-puppeteer/teardown"
  }

app.e2e.js

// IMPORTANT: this test does not run correctly with WSL on Windows
// It **IS** fine on native linux and with a Windows command prompt

describe('describe Home page', () => {
  beforeAll(async () => {
    await page.goto('https://example.com, {waitUntil: 'domcontentloaded'});
  });

  it('should be titled "My Title"', async () => {
    await expect(page.title()).resolves.toMatch('My Title');
  });
});
2 Likes