forked from cypress-io/cypress-vue-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router-spec.js
98 lines (83 loc) · 2.66 KB
/
router-spec.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import PizzaShop from '../../components/PizzaShop'
import router from '../../components/PizzaShop/router'
import VueRouter from 'vue-router'
import mountVue from '../..'
describe('Vue Router - Pizza Shop', () => {
// configure component
const extensions = {
plugins: [VueRouter],
components: {
PizzaShop
}
}
// define component template
const template = '<router-view />'
// initialize a fresh Vue app before each test
beforeEach(mountVue({ template, router }, { extensions }))
it('go to order page', () => {
cy.get('button.order').click()
cy.contains('Toppings')
})
it('order veggie option', () => {
// go back to home page
// from: /order -> to: /
cy.get('a.home').click()
// order a meatlover pizza
// to: /order/meatlover
cy.get('a.order-veggie').click()
.then(() => {
const { path, params } = Cypress.vue.$route
expect(path).to.eql('/order/veggie')
expect(params).to.eql({ preset: 'veggie' })
})
// veggie pizza shouldn't have any meat
// we wouldn't want a lawsuit
for (const topping of ['chicken', 'steak', 'bacon', 'ham']) {
cy.get('.order-overview > ul > li')
.should('not.contain', topping)
}
})
it('order meatlover option', () => {
// go back to home page
// from: /order/veggie -> to: /
cy.get('a.home').click()
.then(() => {
const { path, query, params } = Cypress.vue.$route
expect(path).to.eql('/')
expect(query).to.be.empty
expect(params).to.be.empty
})
// order a meatlover pizza
// to: /order/meatlover
cy.get('a.order-meatlover').click()
.then(() => {
const { path, params } = Cypress.vue.$route
expect(path).to.eql('/order/meatlover')
expect(params).to.eql({ preset: 'meatlover' })
})
})
it('order cheese option', () => {
// directly control the router from your test
cy.wrap(Cypress.vue.$router)
.then($router => $router.push({ name: 'home' }))
// order just a cheese
// to: /order?cheese=true
cy.get('a.order-cheese').click()
.then(() => {
const { path, query } = Cypress.vue.$route
expect(path).to.eql('/order')
expect(query).to.eql({ cheese: true })
})
// cheese topping should be in the order overview
cy.get('.order-overview > ul > li').contains('cheese')
})
it('order hawaian + peppers pizza without using UI', () => {
cy.wrap(Cypress.vue.$router)
.then($router => $router.push({ name: 'home' }))
.then($router => $router.push({
name: 'order',
params: { preset: 'hawaian' },
query: { peppers: true }
}))
})
})