-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
78 lines (59 loc) · 2.27 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// ─── HATCHD UI TESTS ────────────────────────────────────────────────────────────
//
import puppeteer from 'puppeteer';
// the url to the page we are going to run our tests on
const URL = 'https://hatchd.com.au';
let page;
let browser;
// the width and height of the testing browser
const winWidth = 1920;
const winHeight = 1080;
// hook to run before all testing
beforeAll(async () => {
// open the testing browser using our options
browser = await puppeteer.launch({
headless: false,
slowMo: 80,
args: [`--window-size=${winWidth},${winHeight}`]
});
page = await browser.newPage();
await page.setViewport({ width: winWidth, height: winHeight });
});
// hook to run after all testing
afterAll(() => {
// finished testing so close the browser
browser.close();
});
// test the seo
describe('SEO', () => {
test('Title must be present', async () => {
await page.goto(`${URL}`);
const title = await page.title();
// test that the title exists with a regex that will pass any string but an empty one
expect(title).toMatch(/.*\S.*/);
}, 90000);
test('Meta description must be present', async () => {
await page.goto(`${URL}`);
const description = await page.$eval('meta[name="description"]', el => el.content);
// test that the description exists with a regex that will pass any string but an empty one
expect(description).toMatch(/.*\S.*/);
}, 90000);
test('H1 must be present', async () => {
await page.goto(`${URL}`);
const title = await page.$eval('h1', el => el.textContent);
// test that a H1 exists with a regex that will pass any string but an empty one
expect(title).toMatch(/.*\S.*/);
}, 90000);
});
// test the menu functionality
describe('Menu', () => {
test('Menu must open when hamburger clicked', async () => {
await page.goto(`${URL}`);
await page.click('.js-toggle-nav');
const navVisible = await page.$eval('.nav-primary', el => el.style.visibility);
setTimeout(() => {
expect(navVisible).toBe('visible');
}, 100);
}, 90000);
});