-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @jest-environment ./lib/puppeteer/environment.js | ||
*/ | ||
/* eslint-env jest */ | ||
|
||
let browser | ||
let page | ||
let baseUrl = 'http://localhost:3000' | ||
|
||
beforeAll(async (done) => { | ||
browser = global.__BROWSER__ | ||
page = await browser.newPage() | ||
done() | ||
}) | ||
|
||
afterAll(async (done) => { | ||
await page.close() | ||
done() | ||
}) | ||
|
||
describe('/components/button', () => { | ||
describe('/components/button/link', () => { | ||
it('triggers the click event when the space key is pressed', async () => { | ||
await page.goto(baseUrl + '/components/button/link/preview', { waitUntil: 'load' }) | ||
|
||
const href = await page.evaluate(() => document.body.getElementsByTagName('a')[0].getAttribute('href')) | ||
|
||
await page.focus('a[role="button"]') | ||
|
||
// we need to start the waitForNavigation() before the keyboard action | ||
// so we return a promise that is fulfilled when the navigation and the keyboard action are respectively fulfilled | ||
// this is somewhat counter intuitive, as we humans expect to act and then wait for something | ||
await Promise.all([ | ||
page.waitForNavigation(), | ||
page.keyboard.press('Space') | ||
]) | ||
|
||
const url = await page.url() | ||
expect(url).toBe(baseUrl + href) | ||
}) | ||
}) | ||
}) |