Unexpected-knockout

Slam! Boom! Bang!

This module extends the Unexpected assertion library with integration for Knockout.

expect(ko.observable(42), 'to equal', ko.observable(42));
expect(ko.observable(42), 'not to equal', ko.observable(24));
expect(ko.observable(42), 'to be observable');
expect(42, 'not to be observable');
expect(ko.observable(42), 'not to be computed');
expect(ko.computed(function () { return 42 }), 'to be computed');
expect({
    foo: ko.observable(42),
    bar: ko.observable(42),
    baz: 42,
    qux: ko.computed(function () {
        return 42;
    })
}, 'to have properties', {
    foo: ko.observable(42),
    baz: 42,
    qux: ko.computed(function () {
        return 42;
    })
});

Build Status

How to use

Node

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

$ npm install knockout unexpected unexpected-knockout

Then:

var expect = require('unexpected').clone();
expect.installPlugin(require('unexpected-knockout'));

Browser

Include the unexpected-knockout.js found at the lib directory of this repository after unexpected itself:

<!-- Knockout -->
<script src="knockout.js"></script>
<!-- Unexpected -->
<script src="unexpected.js"></script>
<script src="unexpected-knockout.js"></script>

this will expose the expect function under the following namespace:

var expect = weknowhow.expect.clone();
expect.installPlugin(weknowhow.unexpectedKnockout);

RequireJS

Include the library with RequireJS the following way:

define(['unexpected', 'unexpected-knockout'], funtion (unexpected, unexpectedKnockout) {
   var expect = unexpected.clone();
   expect.installPlugin(unexpectedKnockout);
   // Your code
});
Fork me on GitHub