test: add basic tests

cases
This commit is contained in:
EnixCoda 2020-01-14 21:20:58 +08:00
parent 5dd1534a84
commit f97197071f
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
4 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,48 @@
/**
* Make sure some basic behaviors of puppeteer assertions
*/
import { expectToFind, expectToNotFind } from '../utils'
describe(`in random page`, () => {
beforeAll(() => page.goto('https://google.com'))
it('wait for hidden non-exist element should resolve null', async () => {
expect(
await page.waitForSelector('.non-exist-element', { hidden: true, timeout: 1000 }),
).toBeNull()
})
it('wait for exist element', async () => {
expectToFind('*')
})
it('wait for exist element', async () => {
expectToNotFind('.non-exist-element')
})
it('wait for non-exist element reject should throw', async () => {
await expect(page.waitForSelector('.non-exist-element', { timeout: 1000 })).rejects.toThrow()
})
// Cases below are expected to fail to show how async test works
// // This is expected to fail!
// it('wait for non-exist element reject should not throw', async () => {
// await expect(
// page.waitForSelector('.non-exist-element', { timeout: 1000 }),
// ).rejects.not.toThrow()
// })
// // This is expected to fail!
// it('wait for non-exist element should resolve throw', async () => {
// await expect(page.waitForSelector('.non-exist-element', { timeout: 1000 })).resolves.toThrow()
// })
// // This is expected to fail!
// it('wait for non-exist element should resolve not throw', async () => {
// await expect(
// page.waitForSelector('.non-exist-element', { timeout: 1000 }),
// ).resolves.not.toThrow()
// })
})

View file

@ -0,0 +1,9 @@
import { expectToNotFind } from '../utils'
describe(`in GitHub homepage`, () => {
beforeAll(() => page.goto('https://github.com'))
it('should not render Gitako', async () => {
expectToNotFind('.gitako-side-bar .gitako-position-wrapper')
})
})

View file

@ -0,0 +1,9 @@
import { expectToFind } from '../utils'
describe(`in Gitako project page`, () => {
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako'))
it('should render Gitako', async () => {
expectToFind('.gitako-side-bar .gitako-position-wrapper')
})
})

7
__tests__/utils.ts Normal file
View file

@ -0,0 +1,7 @@
export async function expectToFind(selector: string) {
await expect(await page.waitForSelector(selector)).not.toBeNull()
}
export async function expectToNotFind(selector: string) {
await expect(page.waitForSelector(selector, { timeout: 1000 })).rejects.toThrow()
}