Skip to content

Commit

Permalink
modular: added some basic assertion tests for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Sep 17, 2014
1 parent b53061e commit a5514bc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
34 changes: 33 additions & 1 deletion modular/src/client/test/basics/assertions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,39 @@ describe('Basics - assertion examples:', function () {
it('should return -1 when the value is not present', function () {
expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
});

});





describe('when expecting exceptions', function () {
it('passes only if there is an exception', function () {
expect(function () {
throw new Error('my bad');
}).to.throw();
});

it('of a particular Error type', function () {
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
var err = new ReferenceError('This is a bad reference.');
expect(function () {
throw err;
}).to.throw(ReferenceError);
});

it('with a particular message', function () {
expect(function () {
throw new Error('my bad');
}).to.throw(/bad/);
});


it('of a particular Error type with a specific message', function () {
var err = new ReferenceError('This is a bad reference.');
expect(function () {
throw err;
}).to.throw(ReferenceError, /bad reference/);
});
});
});
33 changes: 32 additions & 1 deletion testing/src/client/test/basics/assertions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,38 @@ describe('Basics - assertion examples:', function () {
it('should return -1 when the value is not present', function () {
expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
});

});




describe('when expecting exceptions', function () {
it('passes only if there is an exception', function () {
expect(function () {
throw new Error('my bad');
}).to.throw();
});

it('of a particular Error type', function () {
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
var err = new ReferenceError('This is a bad reference.');
expect(function () {
throw err;
}).to.throw(ReferenceError);
});

it('with a particular message', function () {
expect(function () {
throw new Error('my bad');
}).to.throw(/bad/);
});


it('of a particular Error type with a specific message', function () {
var err = new ReferenceError('This is a bad reference.');
expect(function () {
throw err;
}).to.throw(ReferenceError, /bad reference/);
});
});
});

0 comments on commit a5514bc

Please sign in to comment.