This repository was archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathConfigPatternCache.spec.js
More file actions
74 lines (59 loc) · 2.15 KB
/
ConfigPatternCache.spec.js
File metadata and controls
74 lines (59 loc) · 2.15 KB
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
74
import ConfigPatternCache from '../src/ConfigPatternCache';
import MockConfigContainer from './MockConfigContainer';
describe('ConfigPatternCache', () => {
const container = new MockConfigContainer();
let patternCache;
beforeEach(() => {
patternCache = container.resolve(ConfigPatternCache);
});
describe('#set()', () => {
it('should always add compiled `Function`', () => {
patternCache.set('foo', 'foo');
patternCache.set(1, 2);
expect(patternCache.get('foo')).toEqual(jasmine.any(Function));
expect(patternCache.get(1)).toEqual(jasmine.any(Function));
});
});
describe('#getOrSet()', () => {
it('should `.compile` to `Function` once', () => {
const value1 = patternCache.getOrSet('value'),
value2 = patternCache.getOrSet('value');
expect(value1).toBe(value2);
expect(value1).toEqual(value2);
});
});
describe('#compile()', () => {
it('should compile to `Function`', () => {
expect(patternCache.compile('foo')).toEqual(jasmine.any(Function));
});
});
describe('#eval()', () => {
it('should replace `[foo]` with `bar`', () => {
expect(patternCache.eval('[foo]-[foo]', {
foo: 'bar'
})).toEqual('bar-bar');
expect(patternCache.eval('[ foo ]-[ foo ]', {
foo: 'bar'
})).toEqual('bar-bar');
});
it('should not replace `JSON.stringify`-strings', () => {
const str = JSON.stringify({
foo: [
{ x: 1 },
{ y: 2 },
{ z: 3 }
]
});
expect(patternCache.eval(str, {})).toEqual(str);
});
});
describe('#interpolate', () => {
it('should replace `{foo}` with `bar` using custom `interpolate`', () => {
patternCache.interpolate = /{([\w\s]+?)}/g;
const value = patternCache.eval('{foo}-{foo}', {
foo: 'bar'
});
expect(value).toEqual('bar-bar');
});
});
});