Skip to content

Commit

Permalink
Add button test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ju committed Mar 14, 2018
1 parent 1bc68cf commit 3119acd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/button/button.test.js
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)
})
})
})

0 comments on commit 3119acd

Please sign in to comment.