forked from Faworki/project-catwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppeteerExample.test.js
60 lines (39 loc) · 1.31 KB
/
puppeteerExample.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
const puppeteer = require('puppeteer');
let browser;
let page;
beforeAll(async () => {
// Switch with line below will run the tests and actually open a browser you can see
// browser = await puppeteer.launch({headless: false, slowMo: 100});
browser = await puppeteer.launch();
})
afterAll(async () => {
await browser.close();
})
describe('Project Catwalk', () => {
beforeEach(async () => {
page = await browser.newPage();
})
afterEach(async () => {
await page.close();
})
test('should have title "Project Catwalk"', async () => {
await page.goto('http://localhost:3000/');
const title = await page.title();
expect(title).toBe('Project Catwalk');
})
test('should display 2 review on load', async () => {
await page.goto('http://localhost:3000/', {waitUntil: 'networkidle0'});
let revNum = await page.$eval('.card-container', e => {
return e.childElementCount;
})
expect(revNum).toEqual(2)
})
test('should display 4 reviews after clicking "More Reveiws"', async () => {
await page.goto('http://localhost:3000/', {waitUntil: 'networkidle0'});
/* let click = */await page.click('[data-test="moreReviews"]');
let revNum = await page.$eval('.card-container', e => {
return e.childElementCount;
})
expect(revNum).toEqual(4)
})
})