Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Added tests for assert
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Marcus Stade committed Oct 10, 2014
1 parent f62ef01 commit 4d700cb
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
}
)
})

0 comments on commit 4d700cb

Please sign in to comment.