-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcustomEngines.test.js
More file actions
45 lines (37 loc) · 968 Bytes
/
customEngines.test.js
File metadata and controls
45 lines (37 loc) · 968 Bytes
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
import { LogicEngine, AsyncLogicEngine } from './index.js'
class DataEngine extends LogicEngine {
isData (logic, firstKey) {
if (Object.keys(logic).length > 1) return true
return !(firstKey in this.methods)
}
}
class AsyncDataEngine extends AsyncLogicEngine {
isData (logic, firstKey) {
if (Object.keys(logic).length > 1) return true
return !(firstKey in this.methods)
}
}
const engine = new DataEngine()
const asyncEngine = new AsyncDataEngine()
describe('Custom Engines (isData)', () => {
const logic = {
get: [{
xs: 10,
s: 20,
m: 30
}, {
var: 'size'
}]
}
const data = {
size: 's'
}
it('Should let us override how data is detected (sync)', () => {
const f = engine.build(logic)
expect(f(data)).toEqual(20)
})
it('Should let us override how data is detected (async)', async () => {
const f = await asyncEngine.build(logic)
expect(await f(data)).toEqual(20)
})
})