Skip to content

Instantly share code, notes, and snippets.

View eddyerburgh's full-sized avatar

Edward Wardell-Yerburgh eddyerburgh

View GitHub Profile
@eddyerburgh
eddyerburgh / fill-form-command.js
Created June 7, 2017 12:26
Nightwatch command to fill form with data, similar to casper.fill
// Example data
//
// const values = {
// name: 'Edd',
// lastName: 'Yerburgh',
// }
// Command
const each = require('async/each');
@eddyerburgh
eddyerburgh / vue-test-utils-overview.js
Last active April 8, 2022 11:05
vue-test-utils hasClass example
import { mount } from 'vue-test-utils'
import Component from '@/components/ComponentToTest'
const wrapper = mount(ComponentToTest)
// Traversal
const Foo = wrapper.find(Foo)
const divs = wrapper.findAll('div')
const div = divs.at(0)
import { mount } from 'vue-test-utils'
import ComponentWithSlots from '@/components/ComponentWithSlots'
import AnotherComponent from '@/components/AnotherComponent'
// mount the component with options
const wrapper = mount(ComponentWithSlots, {
slots: {
default: 'div'
},
propsData: {
import { shallow } from 'vue-test-utils'
import ComponentWithChildren from '@/components/ComponentWithSlots'
import ChildComponent from '@/components/AnotherComponent'
// shallow mount the component
const wrapper = mount(ComponentWithChildren)
// you can still find the child component, but it doesn't render any nodes
const childComponent = wrapper.find(ChildComponent)
import { shallow, createLocalVue } from 'vue-test-utils'
import ComponentToTest from '@/components/ComponentsToTest'
const localVue = createLocalVue()
localVue.component('router-link')
localVue.mixin({
created: function () {
console.log('hello')
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
import Vue from 'vue'
import MessageToggle from '@/components/MessageToggle.vue'
describe('MessageToggle.vue', () => {
it('displays default message', () => {
const Ctor = Vue.extend(MessageToggle)
const vm = new Ctor().$mount()
expect(vm.$el.textContent).toContain('default message')
})
import { mount } from '@vue/test-utils'
import MessageToggle from '@/components/MessageToggle.vue'
describe('MessageToggle.vue', () => {
it('displays default message', () => {
const wrapper = mount(MessageToggle)
expect(wrapper.text()).toContain('default message')
})
})
import { mount } from '@vue/test-utils'
import MessageToggle from '@/components/MessageToggle.vue'
describe('MessageToggle.vue', () => {
it('displays default message', () => {
const wrapper = mount(MessageToggle)
expect(wrapper.text()).toContain('default message')
})
it('toggles message when button is clicked', () => {
import { shallow } from '@vue/test-utils'
import List from '@/components/List.vue'
describe('List.vue', () => {
it('renders li for each item in props.items', () => {
const items = ['', '']
const wrapper = shallow(List, {
propsData: { items }
})
expect(wrapper.findAll('li')).toHaveLength(items.length)