GithubHelp home page GithubHelp logo

isabella232 / jest-acceptance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codeship/jest-acceptance

0.0 0.0 0.0 655 KB

Snapshot driven acceptance testing with jest

License: MIT License

TypeScript 100.00%

jest-acceptance's Introduction

jest-acceptance

jest-acceptance is a strategy for getting close to user acceptance quality testing, without the overhead of browser automation.

This strategy attempts to allow for a minimally mocked approach to ensure the interactions your users are having with your components, produce the expected interface changes. We do this by combining Jest's snapshot testing ability, with a serialization strategy that allows you to compare the ways your interface change as a result of user interactions by surfacing the before/after interaction diff as a snapshot itself.

Currently targeted at only Vue applications.

Methods

  • next: returns a promise. Awaits Vue's $nextTick under the hood. When the promise is resolved, it returns the dom's next state.
  • nextSync: returns the next dom state without awaiting $nextTick.
  • current: returns the current dom state.

Usage

import { mount } from '@vue/test-utils'
import Tester from 'jest-acceptance'
import MyApp from './src/index.vue'

describe('MyApp', () => {
  it('should work', async () => {
    // Mount a new component wrapper with `@vue/test-utils`
    const wrapper = mount(MyApp)

    // Create a new instance
    const tester = new Tester(wrapper)

    // Initialize and test initial HTML output
    expect(tester.current()).toMatchSnapshot()

    // Perform some user interactions, producing/checking diffs along the way.
    tester.fillIn('name', 'Jane')
    tester.click({ ref: 'saveBtn' })
    expect(await tester.next()).toMatchSnapshot()

    ui.click({ ref: 'cancelBtn' })
    expect(await tester.next()).toMatchSnapshot()
  })
})

This would produce three snapshots:

  1. The initial rendered HTML of the component
  2. The effect the users interactions have on the HTML, in the form of a diff.
  3. The effect the users interactions have on the HTML, in the form of a diff.

We find the interaction diffs more useful than full repeated HTML snapshots because many times it is very difficult to spot the key interface changes you expect. This approach allows you to follow the diffs like a story.

jest-acceptance's People

Contributors

jondavidjohn avatar passbyval avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.