Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Releases: nadeesha/saul

`expect` and `matches-snapshot` assertions

15 Aug 14:48
Compare
Choose a tag to compare

saul adds two major assertion engines. And deprecates some with this release including contains-dom, and matches-dom. We now advocate virtual dom testing with snapshot testing. (see below)

expect

Assert the result using chai's expect. Comes with test spy support.

Example:

// @t "appends foo" appendFoo('bar') ~expect expect(result).to.contain('foo');
// @t "has no fizz" appendFoo('bar') ~expect expect(result).to.not.contain('fizz');
export function appendFoo (someString) {
    return someString + 'foo';
}

With spy support:

// @t "calls only once"   testEvalSpy(spy('mySpy')) ~expect spy('mySpy').calledOnce
// @t "calls with obj"    testEvalSpy(spy('myOtherSpy'), {leet: 1337}) ~expect expect(spy('myOtherSpy').args[0][1]).to.eql([{leet: 1337}])
export function testEvalSpy (fn, obj) {
  fn('foo', obj);
}

matches-snapshot

Checks whether a previously saved snapshot image of the function's serialized output, matches the current output. (Saves a snapshot file on the first run - that should be checked in to the repo).

Especially useful for testing React components, and inspired by Jest's snapshot testing.

// @t Date({dateString: '1970-03-11'}) ~matches-snapshot
export function Date(props) {
    return <div className={'mydate'}>{props.dateString}</div>
}

// @t getAllMonths() ~matches-snapshot
export function getAllMonths() {
    return CONSTANTS.ALL_MONTHS.join('_');
}

Supporting nested function testing

17 Jun 01:09
Compare
Choose a tag to compare

Saul can now test nested exports.

This means your export default class Foo { bar() {...} } can now be tested with:

// @t "can bar" default.bar() throws false