Skip to content

Commit 5dbb7a6

Browse files
author
Cache Hamm
committed
Move undefined fact detection to almanac.factValue
1 parent 428646e commit 5dbb7a6

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

src/almanac.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ export default class Almanac {
3838
* @return {Fact}
3939
*/
4040
_getFact (factId) {
41-
let fact = this.factMap.get(factId)
42-
if (fact === undefined) {
43-
throw new UndefinedFactError(`Undefined fact: ${factId}`)
44-
}
45-
return fact
41+
return this.factMap.get(factId)
4642
}
4743

4844
/**
@@ -90,6 +86,9 @@ export default class Almanac {
9086
factValue (factId, params = {}, path = '') {
9187
let factValuePromise
9288
let fact = this._getFact(factId)
89+
if (fact === undefined) {
90+
return Promise.reject(new UndefinedFactError(`Undefined fact: ${factId}`))
91+
}
9392
if (fact.isConstant()) {
9493
factValuePromise = Promise.resolve(fact.calculate(params, this))
9594
} else {

test/almanac.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Almanac', () => {
5151
})
5252

5353
it('throws an exception if it encounters an undefined fact', () => {
54-
return expect(almanac.factValue('bar')).to.eventually.be.rejectedWith(/Undefined fact: bar/)
54+
return expect(almanac.factValue('bar')).to.be.rejectedWith(/Undefined fact: bar/)
5555
})
5656
})
5757

@@ -80,11 +80,6 @@ describe('Almanac', () => {
8080
almanac = new Almanac(facts)
8181
expect(almanac._getFact('id')).to.equal(fact)
8282
})
83-
84-
it('raises an exception if fact DNE', () => {
85-
almanac = new Almanac(new Map())
86-
expect(almanac._getFact.bind(almanac, 'unknown')).to.throw(/Undefined fact/)
87-
})
8883
})
8984

9085
describe('_setFactValue()', () => {

0 commit comments

Comments
 (0)