mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
test: add basic tests
cases
This commit is contained in:
parent
5dd1534a84
commit
f97197071f
4 changed files with 73 additions and 0 deletions
48
__tests__/cases/baseline.ts
Normal file
48
__tests__/cases/baseline.ts
Normal 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()
|
||||
// })
|
||||
})
|
||||
9
__tests__/cases/homepage.not-render.ts
Normal file
9
__tests__/cases/homepage.not-render.ts
Normal 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')
|
||||
})
|
||||
})
|
||||
9
__tests__/cases/project-page.gitako.ts
Normal file
9
__tests__/cases/project-page.gitako.ts
Normal 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
7
__tests__/utils.ts
Normal 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()
|
||||
}
|
||||
Loading…
Reference in a new issue