Skip to content

Commit 1e94d0b

Browse files
committed
Add test for example 4
1 parent 851a699 commit 1e94d0b

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

components/Example4.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export default {
3232
<h2>4. Get a random cat with your name</h2>
3333
<p><em>API call done by your browser</em></p>
3434
<ElFormItem label="Name">
35-
<ElInput v-model="form.name" placeholder="Your name" required />
35+
<ElInput data-cy="input-random-cat" v-model="form.name" placeholder="Your name" required />
3636
</ElFormItem>
37-
<ElButton type="primary" @click="randomCat(form.name)">🐈 Meow</ElButton>
37+
<ElButton type="primary" data-cy="btn-random-cat" @click="randomCat(form.name)">🐈 Meow</ElButton>
3838
<p>Response:
39-
<br><br><img v-show="response" :src="response" style="width:100%;height:auto;">
39+
<br><br><img data-cy="img-random-cat" v-show="response" :src="response" style="width:100%;height:auto;">
4040
</p>
4141
<p v-if="error" style="color:red;"><strong>Error {{ error.status }}</strong><br>{{ error.data }}</p>
4242
</ElForm>

test/integration/app.spec.js

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,85 @@ describe('Example 1', () => {
99
})
1010

1111
describe('Example 2', () => {
12-
beforeEach( () => {
12+
beforeEach(() => {
1313
cy.visit('/')
14-
1514
})
15+
1616
it('Defaults to "Hello, World"', () => {
1717
cy.get('[data-cy=btn-hello-name]').click()
1818
cy.contains('Hello, World')
1919
})
20+
2021
it(`Shows "Hello, ${name}"`, () => {
2122
cy.get('[data-cy=input-hello-name]').type(name)
2223
cy.get('[data-cy=btn-hello-name]').click()
2324
cy.contains(`Hello, ${name}`)
2425
})
2526

26-
it("Makes a GET request", () => {
27+
it('Makes a GET request', () => {
2728
cy.server()
2829
cy.route('/.netlify/functions/hello-name').as('getName')
2930
cy.get('[data-cy=btn-hello-name]').click()
3031
})
3132
})
3233

3334
describe('Example 3', () => {
34-
beforeEach( () => {
35+
beforeEach(() => {
3536
cy.visit('/')
3637
cy.server()
3738
cy.route('POST', '/.netlify/functions/hello-name-post').as('postName')
38-
cy.route('GET', '/.netlify/functions/hello-name-post?name=').as('getName')
39+
cy.route('GET', '/.netlify/functions/hello-name-post**').as('getName')
3940
})
41+
4042
it('Defaults to "Hello, World"', () => {
4143
cy.get('[data-cy=btn-hello-name-post]').click()
4244
cy.contains('Hello, World')
43-
cy.wait('@postName').its('method').should('eq', 'POST')
45+
cy.wait('@postName')
46+
.its('method')
47+
.should('eq', 'POST')
4448
})
49+
4550
it(`Shows "Hello, ${name}"`, () => {
4651
cy.get('[data-cy=input-hello-name-post]').type(name)
4752
cy.get('[data-cy=btn-hello-name-post]').click()
4853
cy.contains(`Hello, ${name}`)
49-
cy.wait('@postName').its('method').should('eq', 'POST')
54+
cy.wait('@postName')
55+
.its('method')
56+
.should('eq', 'POST')
5057
})
58+
5159
it(`Throws error 405 Method Not Allowed`, () => {
5260
cy.get('[data-cy=btn-hello-name-post-error]').click()
53-
cy.wait('@getName').then((xhr) => {
61+
cy.wait('@getName').then(xhr => {
5462
expect(xhr.status).to.equal(405)
5563
expect(xhr.method).to.equal('GET')
56-
})
64+
})
5765
cy.contains(`405`)
5866
})
5967
})
68+
69+
describe('Example 4', () => {
70+
beforeEach(() => {
71+
cy.visit('/')
72+
cy.server()
73+
cy.route('GET', '/.netlify/functions/random-cat**').as('getName')
74+
})
75+
76+
it('Defaults to Meow', () => {
77+
cy.get('[data-cy=btn-random-cat]').click()
78+
cy.wait('@getName')
79+
.its('response.body')
80+
.should('include', 'Meow')
81+
cy.contains('Hello, World')
82+
cy.get('[data-cy=img-random-cat]').should('be.visible')
83+
})
84+
85+
it(`Shows "Hello, ${name}"`, () => {
86+
cy.get('[data-cy=input-random-cat]').type(name)
87+
cy.get('[data-cy=btn-random-cat]').click()
88+
cy.wait('@getName')
89+
.its('response.body')
90+
.should('include', name)
91+
cy.get('[data-cy=img-random-cat]').should('be.visible')
92+
})
93+
})

0 commit comments

Comments
 (0)