Skip to content

Commit

Permalink
feat: added example tests for Counter component
Browse files Browse the repository at this point in the history
Added tests to cover all the features within the component. Fixes cypress-io#6
  • Loading branch information
amirrustam committed Jan 26, 2018
1 parent ff428c0 commit 71eddfd
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions cypress/integration/counter-vuex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,51 @@
// https://github.com/vuejs/vuex/tree/dev/examples/counter
import Counter from '../../components/Counter.vue'
import store from '../../components/store'
const mountVue = require('../..')
import Vuex from 'vuex'
import mountVue from '../..'

/* eslint-env mocha */
describe('Vuex Counter', () => {
const extensions = {
const extensions = {
plugins: [Vuex],
components: {
counter: Counter
},
}
const template = '<counter />'
beforeEach(mountVue({template, store}, {extensions}))

const getCount = () =>
Cypress.vue.$store.state.count

const setCount = value => {
Cypress.vue.$store.state.count = value
}

it('starts with zero', () => {
cy.contains('button', '0')
cy.contains('0 times')
})

it('increments the counter on click of "+"', () => {
cy.contains('button', '+').click()
cy.contains('1 times')
})

it('decrements the counter on click of "-"', () => {
cy.contains('button', '-').click()
cy.contains('0 times')
})

it('increments the counter if count is odd', () => {
setCount(3)
cy.contains('odd')
cy.contains('button', 'Increment if odd').click()
cy.contains('even')
})

it('asynchronously increments counter', () => {
let count = getCount()
cy.contains('button', 'Increment async').click()
cy.contains(`${count++} times`)
})
})

0 comments on commit 71eddfd

Please sign in to comment.