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

jest-vue-emotion

v1.0.0

Published

Jest testing utilities for vue-emotion

Downloads

15

Readme

jest-vue-emotion

Jest testing utilities for vue-emotion

Why

Adding snapshot tests with Jest is a great way to help avoid unintended changes to your app's UI.

By diffing the serialized value of your Vue tree Jest can show you what changed in your app and allow you to fix it or update the snapshot.

By default snapshots with vue-emotion show generated class names. Adding jest-vue-emotion allows you to output the actual styles being applied.

Installation

npm install --save-dev jest-vue-emotion

or

yarn add jest-vue-emotion

Snapshot Serializer

The easiest way to test Vue components with vue-emotion is with the snapshot serializer. You can register the serializer via the snapshotSerializers configuration property in your jest configuration like so:

// jest.config.js
module.exports = {
  // ... other config
  snapshotSerializers: ['<rootDir>/node_modules/jest-vue-emotion']
}

Writing a test

Writing a test with jest-vue-emotion involves creating a snapshot from the @vue/test-utils's resulting wrapper.

import Vue from 'vue';
import styled from 'vue-emotion';
import { mount } from '@vue/test-utils';

const Greeting = styled('h1')`
  font-size: 42px;
  color: cornflowerblue;
`;

const StyledComponent = Vue.component('StyledComponent', {
  components: {
    Greeting,
  },
  template: '<Greeting>Hello, world!</Greeting>',
});

describe('StyledComponent', () => {
  it('renders with correct styles', () => {
    const wrapper = mount(StyledComponent);
    expect(wrapper).toMatchSnapshot();
  });
});

It'll create a snapshot that looks like this.

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StyledComponent renders with correct styles 1`] = `
.css-1jiuwsj-Greeting {
  font-size: 42px;
  color: cornflowerblue;
}

<h1 class="css-1jiuwsj-Greeting eyqz2qb0">Hello, world!</h1>
`;

When the styles of a component change, the snapshot will fail and you'll be able to update the snapshot or fix the component.