Skip to content

Commit 71eddfd

Browse files
committed
feat: added example tests for Counter component
Added tests to cover all the features within the component. Fixes cypress-io#6
1 parent ff428c0 commit 71eddfd

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

cypress/integration/counter-vuex-spec.js

+35-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,51 @@
22
// https://github.com/vuejs/vuex/tree/dev/examples/counter
33
import Counter from '../../components/Counter.vue'
44
import store from '../../components/store'
5-
const mountVue = require('../..')
5+
import Vuex from 'vuex'
6+
import mountVue from '../..'
67

78
/* eslint-env mocha */
89
describe('Vuex Counter', () => {
9-
const extensions = {
10+
const extensions = {
11+
plugins: [Vuex],
1012
components: {
1113
counter: Counter
1214
},
1315
}
1416
const template = '<counter />'
1517
beforeEach(mountVue({template, store}, {extensions}))
1618

19+
const getCount = () =>
20+
Cypress.vue.$store.state.count
21+
22+
const setCount = value => {
23+
Cypress.vue.$store.state.count = value
24+
}
25+
1726
it('starts with zero', () => {
18-
cy.contains('button', '0')
27+
cy.contains('0 times')
28+
})
29+
30+
it('increments the counter on click of "+"', () => {
31+
cy.contains('button', '+').click()
32+
cy.contains('1 times')
33+
})
34+
35+
it('decrements the counter on click of "-"', () => {
36+
cy.contains('button', '-').click()
37+
cy.contains('0 times')
38+
})
39+
40+
it('increments the counter if count is odd', () => {
41+
setCount(3)
42+
cy.contains('odd')
43+
cy.contains('button', 'Increment if odd').click()
44+
cy.contains('even')
45+
})
46+
47+
it('asynchronously increments counter', () => {
48+
let count = getCount()
49+
cy.contains('button', 'Increment async').click()
50+
cy.contains(`${count++} times`)
1951
})
2052
})

0 commit comments

Comments
 (0)