This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.js
73 lines (60 loc) · 1.57 KB
/
spec.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eslint-env mocha */
const snapshot = require('snap-shot-it')
const la = require('lazy-ass')
const is = require('check-more-types')
const sinon = require('sinon')
describe('feature-maybe', () => {
const featureMaybe = require('.')
let feature
it('is a function', () => {
la(is.fn(featureMaybe))
})
beforeEach(() => {
const features = {
wizard: true,
mode: 'beast',
admin: false
}
feature = featureMaybe(features)
})
it('returns a function', () => {
la(is.fn(feature))
})
it('returns wizard', () => {
snapshot(feature('wizard'))
})
it('returns mode', () => {
snapshot(feature('mode'))
})
it('does not have feature foo', () => {
snapshot(feature('foo'))
})
it('maps if existing feature', () => {
const spy = sinon.spy()
feature('wizard').map(spy)
la(spy.calledOnce)
})
it('passes value to existing feature', () => {
const spy = sinon.spy()
feature('mode')
.map(value => {
la(value === 'beast')
})
.map(spy)
la(spy.calledOnce)
})
it('calls .orElse for non-existing features', () => {
const onFeature = sinon.spy()
const onNoFeature = sinon.spy()
feature('foo').map(onFeature).orElse(onNoFeature)
la(!onFeature.called)
la(onNoFeature.calledOnce)
})
it('knows admin feature is off', () => {
const onFeature = sinon.spy()
const onNoFeature = sinon.spy()
feature('admin').map(onFeature).orElse(onNoFeature)
la(!onFeature.called, 'onFeature was called')
la(onNoFeature.calledOnce, 'onNoFeature was not called')
})
})