|
1 |
| -const name = 'Marco' |
2 |
| - |
3 |
| -describe('Example 1', () => { |
4 |
| - it('Shows Hello, World', () => { |
5 |
| - cy.visit('/') |
6 |
| - cy.get('[data-cy=btn-hello-world]').click() |
7 |
| - cy.contains('Hello, World') |
8 |
| - }) |
9 |
| -}) |
10 |
| - |
11 |
| -describe('Example 2', () => { |
12 |
| - beforeEach(() => { |
13 |
| - cy.visit('/') |
14 |
| - }) |
15 |
| - |
16 |
| - it('Defaults to "Hello, World"', () => { |
17 |
| - cy.get('[data-cy=btn-hello-name]').click() |
18 |
| - cy.contains('Hello, World') |
19 |
| - }) |
20 |
| - |
21 |
| - it(`Shows "Hello, ${name}"`, () => { |
22 |
| - cy.get('[data-cy=input-hello-name]').type(name) |
23 |
| - cy.get('[data-cy=btn-hello-name]').click() |
24 |
| - cy.contains(`Hello, ${name}`) |
25 |
| - }) |
26 |
| -}) |
27 |
| - |
28 |
| -describe('Example 3', () => { |
29 |
| - beforeEach(() => { |
30 |
| - cy.visit('/') |
31 |
| - cy.server() |
32 |
| - cy.route('POST', '/.netlify/functions/hello-name-post').as('postName') |
33 |
| - cy.route('GET', '/.netlify/functions/hello-name-post**').as('getName') |
34 |
| - }) |
35 |
| - |
36 |
| - it('Defaults to "Hello, World"', () => { |
37 |
| - cy.get('[data-cy=btn-hello-name-post]').click() |
38 |
| - cy.contains('Hello, World') |
39 |
| - cy.wait('@postName').its('method').should('eq', 'POST') |
40 |
| - }) |
41 |
| - |
42 |
| - it(`Shows "Hello, ${name}"`, () => { |
43 |
| - cy.get('[data-cy=input-hello-name-post]').type(name) |
44 |
| - cy.get('[data-cy=btn-hello-name-post]').click() |
45 |
| - cy.contains(`Hello, ${name}`) |
46 |
| - cy.wait('@postName').its('method').should('eq', 'POST') |
47 |
| - }) |
48 |
| - |
49 |
| - it(`Throws error 405 Method Not Allowed`, () => { |
50 |
| - cy.get('[data-cy=btn-hello-name-post-error]').click() |
51 |
| - cy.wait('@getName').then((xhr) => { |
52 |
| - expect(xhr.status).to.equal(405) |
53 |
| - expect(xhr.method).to.equal('GET') |
54 |
| - }) |
55 |
| - cy.contains(`405`) |
56 |
| - }) |
57 |
| -}) |
58 |
| - |
59 |
| -describe('Example 4', () => { |
60 |
| - beforeEach(() => { |
61 |
| - cy.visit('/') |
62 |
| - cy.server() |
63 |
| - cy.route('GET', '/.netlify/functions/random-cat**').as('getName') |
64 |
| - }) |
65 |
| - |
66 |
| - it('Defaults to Meow', () => { |
67 |
| - cy.get('[data-cy=btn-random-cat]').click() |
68 |
| - cy.wait('@getName').its('response.body').should('include', 'Meow') |
69 |
| - cy.contains('Hello, World') |
70 |
| - cy.get('[data-cy=img-random-cat]').should('be.visible') |
71 |
| - }) |
72 |
| - |
73 |
| - it(`Shows "Hello, ${name}"`, () => { |
74 |
| - cy.get('[data-cy=input-random-cat]').type(name) |
75 |
| - cy.get('[data-cy=btn-random-cat]').click() |
76 |
| - cy.wait('@getName').its('response.body').should('include', name) |
77 |
| - cy.get('[data-cy=img-random-cat]').should('be.visible') |
78 |
| - }) |
79 |
| -}) |
| 1 | +const name = 'Marco' |
| 2 | + |
| 3 | +describe('Example 1', () => { |
| 4 | + it('Shows Hello, World', () => { |
| 5 | + cy.visit('/') |
| 6 | + cy.get('[data-cy=btn-hello-world]').click() |
| 7 | + cy.contains('Hello, World') |
| 8 | + }) |
| 9 | +}) |
| 10 | + |
| 11 | +describe('Example 2', () => { |
| 12 | + beforeEach(() => { |
| 13 | + cy.visit('/') |
| 14 | + }) |
| 15 | + |
| 16 | + it('Defaults to "Hello, World"', () => { |
| 17 | + cy.get('[data-cy=btn-hello-name]').click() |
| 18 | + cy.contains('Hello, World') |
| 19 | + }) |
| 20 | + |
| 21 | + it(`Shows "Hello, ${name}"`, () => { |
| 22 | + cy.get('[data-cy=input-hello-name]').type(name) |
| 23 | + cy.get('[data-cy=btn-hello-name]').click() |
| 24 | + cy.contains(`Hello, ${name}`) |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +describe('Example 3', () => { |
| 29 | + beforeEach(() => { |
| 30 | + cy.visit('/') |
| 31 | + cy.server() |
| 32 | + cy.route('POST', '/.netlify/functions/hello-name-post').as('postName') |
| 33 | + cy.route('GET', '/.netlify/functions/hello-name-post**').as('getName') |
| 34 | + }) |
| 35 | + |
| 36 | + it('Defaults to "Hello, World"', () => { |
| 37 | + cy.get('[data-cy=btn-hello-name-post]').click() |
| 38 | + cy.contains('Hello, World') |
| 39 | + cy.wait('@postName').its('method').should('eq', 'POST') |
| 40 | + }) |
| 41 | + |
| 42 | + it(`Shows "Hello, ${name}"`, () => { |
| 43 | + cy.get('[data-cy=input-hello-name-post]').type(name) |
| 44 | + cy.get('[data-cy=btn-hello-name-post]').click() |
| 45 | + cy.contains(`Hello, ${name}`) |
| 46 | + cy.wait('@postName').its('method').should('eq', 'POST') |
| 47 | + }) |
| 48 | + |
| 49 | + it(`Throws error 405 Method Not Allowed`, () => { |
| 50 | + cy.get('[data-cy=btn-hello-name-post-error]').click() |
| 51 | + cy.wait('@getName').then((xhr) => { |
| 52 | + expect(xhr.status).to.equal(405) |
| 53 | + expect(xhr.method).to.equal('GET') |
| 54 | + }) |
| 55 | + cy.contains(`405`) |
| 56 | + }) |
| 57 | +}) |
| 58 | + |
| 59 | +describe('Example 4', () => { |
| 60 | + beforeEach(() => { |
| 61 | + cy.visit('/') |
| 62 | + cy.server() |
| 63 | + cy.route('GET', '/.netlify/functions/random-cat**').as('getName') |
| 64 | + }) |
| 65 | + |
| 66 | + it('Defaults to Meow', () => { |
| 67 | + cy.get('[data-cy=btn-random-cat]').click() |
| 68 | + cy.wait('@getName').its('response.body').should('include', 'Meow') |
| 69 | + cy.contains('Hello, World') |
| 70 | + cy.get('[data-cy=img-random-cat]').should('be.visible') |
| 71 | + }) |
| 72 | + |
| 73 | + it(`Shows "Hello, ${name}"`, () => { |
| 74 | + cy.get('[data-cy=input-random-cat]').type(name) |
| 75 | + cy.get('[data-cy=btn-random-cat]').click() |
| 76 | + cy.wait('@getName').its('response.body').should('include', name) |
| 77 | + cy.get('[data-cy=img-random-cat]').should('be.visible') |
| 78 | + }) |
| 79 | +}) |
0 commit comments