npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@behance/jasmine-vue

v1.0.0

Published

Jasmine test helper for Vue files

Downloads

9

Readme

jasmine-vue npm

Jasmine test helper for Vue components

Requires jasmine.

Install

$ 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.

Setup

Include jasmine-vue in the root file of your tests using require.

require('jasmine-vue');

Initialization

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);
});

Mounting / Rendering Components

Use the creator returned from vueInit to mount the component.

creator.mount( { [customPropsData], [store], [componentOverrides], el } )

  • Arguments:
    • {Object} customPropsData (optional)
      • will overwrite defaultProps passed into vueInit, otherwise defaults to them
    • {Object} store (optional)
      • creates a new Vuex.Store on the passed-in object and sets it on the instance
    • {Object} componentOverrides (optional)
      • will override any instance properties
      • can be used to spy on or stub lifecycle methods
    • {String|Element} El (optional)
      • will mount Vue component to an element selector or to an element that is passed in
      • if left blank, it will mount to body
  • Usage:

Without 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();
});

creator.mountSolo( { [customPropsData], [store], [componentOverrides], el } )

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();
});

Clean up

In each afterEach phase, if components have been mounted, jasmine-vue will automatically remove the component DOM element and call Vue's $destroy method.

vuePreventDestroy

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.

License

Apache-2.0