From 4d700cb3e14ac9687ebe0d15cc7bbf8aa11c8930 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Fri, 10 Oct 2014 12:15:44 +0100 Subject: [PATCH] Added tests for `assert` A bit shameful to not have these. diff --git a/test/assert.js b/test/assert.js new file mode 100644 index 0000000..0ebdab4 --- /dev/null +++ b/test/assert.js @@ -0,0 +1,52 @@ +var expect = require('chai').expect + , assert = require('../lib/assert') + , each = require('../lib/each') + , src = require('../lib/src') + , $ = require('../lib/partial') + +describe('assert', function() { + each( + [ null + , false + , undefined + ] + , + function(x) { + describe('when given `' + src(x) + '`', function() { + it('should throw an error with the message `Assertion failed.`', function() { + expect($(assert, x)).to.throw('Assertion failed.') + }) + + describe('and also given the message `:o(`', function() { + it('should throw an error with the message `:o(`', function() { + expect($(assert, x, ':o(')).to.throw(':o(') + }) + }) + + describe('and also given an instance of Error', function() { + it('should throw that error', function() { + var err = new Error('sad face') + expect($(assert, x, err)).to.throw(err) + }) + }) + }) + } + ) + + each( + [ 0 + , '' + , {} + , [] + ] + , + function(x) { + describe('when given `' + src(x) + '`', function() { + it('should not throw an error and return the value', function() { + expect($(assert, x)).to.not.throw + expect(assert(x)).to.equal(x) + }) + }) + } + ) +}) \ No newline at end of file --- test/assert.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/assert.js diff --git a/test/assert.js b/test/assert.js new file mode 100644 index 0000000..0ebdab4 --- /dev/null +++ b/test/assert.js @@ -0,0 +1,52 @@ +var expect = require('chai').expect + , assert = require('../lib/assert') + , each = require('../lib/each') + , src = require('../lib/src') + , $ = require('../lib/partial') + +describe('assert', function() { + each( + [ null + , false + , undefined + ] + , + function(x) { + describe('when given `' + src(x) + '`', function() { + it('should throw an error with the message `Assertion failed.`', function() { + expect($(assert, x)).to.throw('Assertion failed.') + }) + + describe('and also given the message `:o(`', function() { + it('should throw an error with the message `:o(`', function() { + expect($(assert, x, ':o(')).to.throw(':o(') + }) + }) + + describe('and also given an instance of Error', function() { + it('should throw that error', function() { + var err = new Error('sad face') + expect($(assert, x, err)).to.throw(err) + }) + }) + }) + } + ) + + each( + [ 0 + , '' + , {} + , [] + ] + , + function(x) { + describe('when given `' + src(x) + '`', function() { + it('should not throw an error and return the value', function() { + expect($(assert, x)).to.not.throw + expect(assert(x)).to.equal(x) + }) + }) + } + ) +}) \ No newline at end of file