This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathand.js
50 lines (43 loc) · 1.54 KB
/
and.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const constantly = require('../lib/constantly')
, expect = require('must')
, and = require('../lib/and')
describe('`and`', function() {
describe('given zero arguments', function() {
it('should return `true`', function() {
expect(and()).to.equal(true)
})
})
describe('given one argument', function() {
it('should return the value of that argument', function() {
expect(and(1)).to.equal(1)
expect(and(0)).to.equal(0)
expect(and(false)).to.equal(false)
})
describe('and when that argument is a function', function() {
it('should return the value of calling that function', function() {
expect(and(constantly('wibble'))).to.equal('wibble')
})
})
})
describe('given two or more arguments', function() {
describe('when the values of all arguments are logically true', function() {
it('should return the last supplied value', function() {
expect(and(0, 1, 2, 3)).to.equal(3)
})
})
describe('when any one argument is logically false', function() {
it('should return the value that was logically false', function() {
expect(and(0, null, 1)).to.equal(null)
expect(and(false, true, 1)).to.equal(false)
expect(and(0, true, undefined)).to.equal(undefined)
})
})
describe('when an argument is a function', function() {
it('should call the function and evaluate its return value', function() {
var called = false
expect(and(0, function() { return (called = true) }, 1, 'yup')).to.equal('yup')
expect(called).to.be.true
})
})
})
})