GithubHelp home page GithubHelp logo

zopf's Introduction

zopf

MIT licensed Build Status js-standard-style Dependency Status

If you're running a bunch of tests:

  • Transpiled from another languages (ES2015 to ES5 via babel, for example) and for which you'd like stack traces in the original language
  • That use sinon to spy, stub and mock things
  • That sometimes return promises
  • That should fail individually when they throw

...and you want to avoid setting all that up yourself for every test case or file, then zopf just might be for you.

Usage & examples

zopf is actually a thin wrapper over tape, which means you can use it pretty much the same:

var test = require('zopf')

test('basic test', function (t) {
  t.is(true, true)
})

You don't need to call t.end().

If you return a Promise, the test will be async and will pass if no assertion fail and the promise resolves.

If you return something else, the test will end there.

The context, t, is augmented with a sinon sandbox that lets you create spies, stubs and mocks, and verifies all of them at the end of the test.

import test from 'zopf'
import Promise from 'bluebird'

let foo = {
  bar: () => Promise.resolve('Uh oh.')
}

test('using promises', t => {
  let mock = t.mock(foo)
  mock.expects('bar').returns(Promise.resolve('Success!'))

  return foo.bar().then(res => {
    t.is(res, 'Success!')
  })
})

In that last example:

  • If foo.bar() rejects, the test will fail
  • If foo.bar() resolves without calling our mock, the test will fail when the sinon sandbox is verified
  • If foo.bar() resolves, our mock has been called, but the return value is wrong, the test will fail

Running tests

Simply use tape to run your zopf tests - as long as you require('zopf') instead of require('tape') you'll get all the zopf niceties for free.

The best way is probably to run npm install --save-dev tape and add an npm script to your package.json:

{
  "name": "yourpackage",
  "scripts": {
    "test": "tape spec/*-test.js"
  }
}

Name meaning / pronunciation

Zopf is a type of Swiss bread, which basically means braid. It seemed appropriate for this module as it braids together several test facilities and was short and available on npm.

License

Licensed under MIT License, see LICENSE for details.

zopf's People

Contributors

fasterthanlime avatar

Watchers

James Cloos avatar  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.