Coder Social home page Coder Social logo

cup-of-unexpected's Introduction

cup-of-unexpected

A reimplementation of the chaijs.expect interface using Unexpected.

NPM version Build Status Coverage Status

This module intends to be a drop-in replacement for projects using the expect() interface of the Chai Assertion Library. The set of supported assertions is close both in terms of API and behaviour as is possible.

Getting started

Take the following test suite:

var chai = require('chai');
var expect = chai.expect;

describe('add', function() {
  it('should return a number', function() {
    var result = add(1, 2);
    expect(result).to.be.a('number');
  });

  it('should add to numbers correctly', function() {
    var result = add(2, 2);
    expect(result).to.eql(3);
  });
});

With cup-of-unexpected installed:

$ npm install --save-dev expect-the-unexpected

Switching the test suite over is as simple as:

-var chai = require('chai');
+var chai = require('cup-of-unexpected');

Any tests you're written will continue to execute unchaged.

Unsupported features

The primary functionality that we do not currently support is plugins.

Custom Assertions

While chai plugins are not suported the library does support the use of Unexpected plugins. These are implemented differrently and are localised to an instance of expect being used to avoid having any extensions bleed over into other parts of the test suite.

Let's use an example of an assertion intended to be used in the browser to check whether a particular DOM node has a CSS class. We can implement this using the Unexpected assertion syntax and add it directly via the fully compatible addAssertion() API:

expect.addAssertion('[not] to have css class', function(
  expect,
  subject,
  value
) {
  var $element = $(subject);
  var elementClasses = ($element.attr('class') || '').split(' ');
  expect(elementClasses, '[not] to contain', value);
});

The assertion can then be used like any other expect assertion by using its dotted path name:

var html = '<div class="foo bar baz"></div>';

expect(html).to.have.css.class('foo');

License

This module is published under the ISC license. See the LICENSE file for details.

cup-of-unexpected's People

Contributors

alexjeffburke avatar gustav-olsen-groupone avatar gustavnikolaj avatar papandreou avatar sunesimonsen avatar

Watchers

 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.