Welcome to Unexpected

The extensible BDD assertion toolkit

expect({ text: 'f00!' }, 'to equal', { text: 'foo!' });
expected { text'f00!' } to equal { text'foo!' }
 
{
  
text
'f00!'
 
//
//
//
//
 
should equal 
'foo!'
 
f00!
foo!
}

Badges

NPM version Build Status Coverage Status Dependency Status Gitter Github

Features

Node

Install it with NPM or add it to your package.json:

$ npm install --save-dev unexpected

Then:

var expect = require('unexpected');

Browser

Include unexpected.js.

<script src="unexpected.js"></script>

This will expose the expect function under the following namespace:

var expect = weknowhow.expect;

RequireJS

Include the library with RequireJS the following way:

require.config({
    paths: {
        unexpected: 'path/to/unexpected'
    }
});
 
define(['unexpected'], function (expect) {
   // Your code
});

Using Unexpected with a test framework

For example, if you create a test suite with mocha.

Let's say we wanted to test the following program:

math.js

function add (a, b) { return a + b; };

Our test file would look like this:

describe('math.js', function () {
  describe('add', function () {
    it('is a function', function () {
      expect(add, 'to be a', 'function');
    });
 
    it('adds numbers', function () {
      expect(add(1, 3), 'to be', 4);
    });
  });
});

If a certain expectation fails, an exception will be raised which gets captured and shown/processed by the test runner.

Source

The source for Unexpected can be found on Github.

Releases

10.0.0

9.0.0

8.0.0

7.0.0

6.0.0

Configure the error output

Disable stack trace trimming

You can disable stack trace trimming the following way:

UNEXPECTED_FULL_TRACE=true mocha

You can achieve the same in the browser by setting the query parameter full-trace to true.

Controlling the inspection depth

To change the level subtrees gets dotted out, you can set the inspection depth the following way:

UNEXPECTED_DEPTH=9 mocha

You can achieve the same in the browser by setting the query parameter depth to the inspection depth you want.

MIT License

Copyright (c) 2013 Sune Simonsen sune@we-knowhow.dk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Fork me on GitHub