-
Notifications
You must be signed in to change notification settings - Fork 490
/
Copy pathfact.test.js
48 lines (41 loc) · 1.34 KB
/
fact.test.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
'use strict'
import { Fact } from '../src/index'
describe('Fact', () => {
function subject (id, definition, options) {
return new Fact(id, definition, options)
}
describe('Fact::constructor', () => {
it('works for constant facts', () => {
const fact = subject('factId', 10)
expect(fact.id).to.equal('factId')
expect(fact.value).to.equal(10)
})
it('works for dynamic facts', () => {
const fact = subject('factId', () => 10)
expect(fact.id).to.equal('factId')
expect(fact.calculate()).to.equal(10)
})
it('allows options to be passed', () => {
const opts = { test: true, cache: false }
const fact = subject('factId', 10, opts)
expect(fact.options).to.eql(opts)
})
describe('validations', () => {
it('throws if no id provided', () => {
expect(subject).to.throw(/factId required/)
})
})
})
describe('Fact::types', () => {
it('initializes facts with method values as dynamic', () => {
const fact = subject('factId', () => {})
expect(fact.type).to.equal(Fact.DYNAMIC)
expect(fact.isDynamic()).to.be.true()
})
it('initializes facts with non-methods as constant', () => {
const fact = subject('factId', 2)
expect(fact.type).to.equal(Fact.CONSTANT)
expect(fact.isConstant()).to.be.true()
})
})
})