This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the action | |
[actionTypes.ACTION_SET_FAV_ELEM] (context, elemId) { | |
context.commit(mutationTypes.MUTATION_SET_FAV_ELEM, elemId) | |
} | |
// the test | |
it('should invoke mutation to set the favourite element', done => { | |
const elemId = 'AAAAAA' | |
testAction(actions[actionTypes.ACTION_SET_FAV_ELEM], elemId, {}, [ | |
{ type: mutationTypes.MUTATION_SET_FAV_ELEM, payload: elemId } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the action | |
[actionTypes.ACTION_SET_FAV_ELEM] (context) { | |
return APIAdapter.services.fetchFavElem() | |
.then((response) => { | |
context.commit(mutationTypes.MUTATION_SET_FAV_ELEM, response) | |
resolve(true) | |
}).catch((error) => { | |
context.commit(mutationTypes.MUTATION_SET_FAV_ELEM, undefined) | |
reject(error) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the mutation | |
[mutationTypes.MUTATION_SET_FAV_ELEM] (state, elemId) { | |
state.favElem = elemId | |
} | |
// the test | |
it('should set state.favElem', () => { | |
const state = { | |
favElem: '' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the getter | |
getElemsByCategory: state => (category) => { | |
return state.elems.filter((el, index, arr) => el.category === category) | |
} | |
// the test | |
it('should return the elements that have Cat1 as category', done => { | |
const expected = [ | |
{ | |
'id': '1', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div></div> | |
</template> | |
<script> | |
export default { | |
// == Lifecycle | |
mounted () { | |
window.addEventListener('scroll', this.handleScroll) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Basic component', () => { | |
describe('Lifecycle', () => { | |
it('Mounted', done => { | |
const handleScrollStub = sinon.stub(BasicComponent.methods, 'handleScroll') | |
const addEventStub = sinon.stub(window, 'addEventListener') | |
const wrapper = mount(BasicComponent) | |
expect(addEventStub).to.be.calledWith('scroll', wrapper.vm.handleScroll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div></div> | |
</template> | |
<script type="text/javascript"> | |
export default { | |
... | |
data () { | |
return { | |
currentObjects: [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Objects component', () => { | |
describe('Methods', () => { | |
it('getObjects - should return true and set the data.currentObjects if getObjects retrieves an array of objects', done => { | |
const mockedObjects = [ | |
{ id: 1 }, | |
{ id: 2 } | |
] | |
const wrapper = mount(ObjectsComponent) | |
const getObjectsStub = sinon.stub(wrapper.vm, 'getObjects').returns(mockedObjects) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div></div> | |
</template> | |
<script type="text/javascript"> | |
import { GET_OBJECTS } from 'services/constants/action-types' | |
export default { | |
... | |
data () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GET_OBJECTS } from 'services/constants/action-types' | |
describe('Objects component', () => { | |
let store | |
let state | |
let actions | |
beforeEach(() => { | |
actions = {} | |
actions[GET_OBJECTS] = sinon.stub() |
OlderNewer