Skip to content

Instantly share code, notes, and snippets.

@binaryk
Last active March 19, 2018 12:03
Show Gist options
  • Save binaryk/e953df075e61b9bd0d14461e6fe513a5 to your computer and use it in GitHub Desktop.
Save binaryk/e953df075e61b9bd0d14461e6fe513a5 to your computer and use it in GitHub Desktop.
Mock for all .spec.js tests, just replace <ComponentName> with your (file) component, and uncomment useful code or remove useless.
import Vue from 'vue';
import Vuex from 'vuex';
import sinon from 'sinon';
import flushPromises from 'flush-promises';
import { createLocalVue, mount } from '@vue/test-utils';
import elementOnDemand from 'src/plugins/element-on-demand';
import ComponentName from './ComponentName';
import { modules } from 'src/store/index';
import { mapUse } from 'src/helpers';
const localVue = createLocalVue();
mapUse([
elementOnDemand
], localVue);
describe('ComponentName', () => {
let // actionMethodCheckedToBeCalled = sinon.stub().returns({ issues: [] }),
// $notify = sinon.stub(),
/* someComputed = () => () => {
return {
triggers: [ {
subTriggers: [ {
field: '',
lowerThreshold: '',
upperThreshold: ''
} ]
}]
}
},*/
wrapper,
store,
computed = {
// someComputed: someComputed,
},
methods = {
// actionMethodCheckedToBeCalled
},
/* $route = {
params: {
id: 'test'
}
},*/
mocks = {
// $route,
// $notify
},
buildComponent = args => mount(ComponentName, {localVue, store, ...args});
beforeEach(() => {
// modules.units.getters.getUnitById = () => () => dummyCompany;
// modules.user.state.userInfo = {_id: 'test'};
/* // Overwrite some state
modules.foo.state.someState = {
[ unitId ]: {
foo: [ {
issueType: 'Alarm',
source: {
sourceId: 'test'
}
} ]
}
};*/
store = new Vuex.Store({ modules });
wrapper = buildComponent({ methods, mocks, computed });
wrapper.setData({});
wrapper.setProps({});
});
afterEach(() => {
// actionMethodCheckedToBeCalled = sinon.stub().returns({ issues: [] }),
// methods.actionMethodCheckedToBeCalled = actionMethodCheckedToBeCalled;
})
it('should render', async () => {
await flushPromises();
expect(1).toBe(1);
// expect(actionMethodCheckedToBeCalled.called).toBe(false);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment