
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@behance/jasmine-vue
Advanced tools
Jasmine test helper for Vue components
Requires
jasmine.
$ npm install --save-dev jasmine-vue
Jasmine Vue abstracts away some of the boilerplate required when testing Vue components. Currently it helps with the setup, mounting, and destruction of a component.
Include jasmine-vue in the root file of your tests using require.
require('jasmine-vue');
A vueInit function will be available in the test context. It returns a creator object that is used to mount component instances. vueInit takes in an optional set of default props. It will generally only need to be called once per component test file.
beforeEach(function() {
const defaultProps = {
myProp: true,
};
// Initialize
this.componentCreator = this.vueInit(MyComponent, defaultProps);
});
Use the creator returned from vueInit to mount the component.
defaultProps passed into vueInit, otherwise defaults to themnew Vuex.Store on the passed-in object and sets it on the instanceWithout any arguments:
it('renders my component with default props', function() {
const vm = this.componentCreator.mount();
expect($(vm.$el)).toBeInDOM(); // using jasmine-jquery
expect(vm.myProp).toEqual(true);
});
With custom props data:
it('renders my component using custom props', function() {
const vm = this.componentCreator.mount({ propsData: { myProp: false } });
expect(vm.myProp).toEqual(false);
});
With a store:
it('renders my component using custom props and a Vuex store', function() {
const vm = this.componentCreator.mount({}, {
state: {
text: 'abc123',
},
});
expect(vm.$store.state.text).toEqual('abc123');
});
With a component override:
it('renders my component using custom props and a Vuex store', function() {
const spy = jasmine.createSpy('spy');
const vm = this.componentCreator.mount({}, {}, {
beforeMount: spy
});
expect(spy).toHaveBeenCalled();
});
beforeEach(function() {
this.vm = this.componentCreator.mount();
});
it('clears all previously mounted components and mounts a solo component', function() {
const soloVm = this.componentCreator.mountSolo();
expect($(this.vm.$el)).not.toBeInDOM();
expect($(soloVm.$el)).toBeInDOM();
});
In each afterEach phase, if components have been mounted, jasmine-vue will automatically remove the component DOM element and call Vue's $destroy method.
Available as this.vuePreventDestroy, this method will disable the afterEach cleanup of components. This (combined with fit or fdescribe) allows for some nice sandboxing of components. Focus the test, call this.vuePreventDestroy, and open the browser and access the component in its current state. Unlike using the debugger, this allows for interacting with the component in it's current state.
FAQs
Jasmine test helper for Vue files
We found that @behance/jasmine-vue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.