@eddyerburgh
E2E
tests
Snapshot tests
Unit tests
end-to-end tests
browser
.url(devServerURL)
.waitForElementVisible('#app', 5000)
.click('.modal button')
.assert.elementNotPresent('.modal')
.end()
E2E
tests
// sum.js
function sum (a, b) {
return a + b
}
export default sum
// sum.spec.js
import sum from './sum'
test('returns sum of input', () => {
expect(sum(1,3)).toBe(4)
})
import { mount } from '@vue/test-utils'
import Modal from '../Modal.vue'
test('Modal does not render', {
})
import { mount } from '@vue/test-utils'
import Modal from '../Modal.vue'
test('Modal does not render', {
const wrapper = mount(Modal)
expect(wrapper.isEmpty()).toBe(true)
})
import { mount } from '@vue/test-utils'
import Modal from '../Modal.vue'
test('Modal does not render', {
const wrapper = mount(Modal)
})
import { mount } from '@vue/test-utils'
import Modal from '../Modal.vue'
test('Modal renders correct div', {
const wrapper = mount(Modal)
expect(wrapper.find('div.a-class')
.exists()).toBe(true)
})
import { mount } from '@vue/test-utils'
import Modal from '../Modal.vue'
test('Modal renders correct div', {
const wrapper = mount(Modal)
expect(wrapper.find('div.another-class')
.exists()).toBe(true)
})
Component
<modal-component
:visible="displayModal"
:onClose="closeModal"
>
Some content
</modal-component>
test('calls onClose when button is clicked')
test('does not render when not passed visible prop')
test('renders when passed visible prop as true')
test('calls onClose when button is clicked')
test('does not render when not passed visible prop')
test('calls onClose when button is clicked')
<template>
<div v-if="visible">
<button @click="onClose" />
</div>
</template>
<script>
export default {
props: ['visible', 'onClose']
}
</script>
<template>
<div v-if="visible" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-content">
<div class="box">
<button
@click="onClose"
class="delete"
aria-label="close"></button>
<slot />
</div>
</div>
</div>
</div>
</template>
test('renders correctly', () => {
const wrapper = mount(Modal, {
propsData: {
visible: true
}
})
})
test('renders correctly', () => {
})
test('renders correctly', () => {
const wrapper = mount(Modal, {
propsData: {
visible: true
}
})
expect(wrapper.html()).toMatchSnapshot()
})
Does previous
snapshot exist?
create snapshot
compare to previous
snapshot
test passes
No
Yes
does output
match
snapshshot?
create snapshot file
test fails
test passes
Yes
No
E2E
tests
Snapshot tests
Unit tests