|
1 | | - |
2 | 1 | import { replaceVariables } from '@common/utils/variables'; |
3 | | - |
4 | 2 | import { expect } from 'chai'; |
5 | 3 |
|
6 | 4 | describe('Utils | variables', () => { |
7 | 5 | describe('replaceVariables', () => { |
8 | 6 | const variables = { |
9 | | - 'name': 'bob', |
10 | | - 'age': 32, |
11 | | - 'favFoods': [ |
12 | | - 'takoyaki', 'onigiri', 'taiyaki' |
13 | | - ], |
14 | | - 'job': { |
15 | | - 'company': 'voiceflow', |
16 | | - 'position': 'software engineer', |
17 | | - 'team': 'creator' |
18 | | - } |
| 7 | + name: 'bob', |
| 8 | + age: 32, |
| 9 | + favFoods: ['takoyaki', 'onigiri', 'taiyaki'], |
| 10 | + job: { |
| 11 | + company: 'voiceflow', |
| 12 | + position: 'software engineer', |
| 13 | + team: 'creator', |
| 14 | + }, |
19 | 15 | }; |
20 | 16 | it('correctly replaces simple variables', () => { |
21 | | - expect(replaceVariables('hello, my name is {name}, and i am {age} years old', variables)) |
22 | | - .to.eq('hello, my name is bob, and i am 32 years old'); |
23 | | - expect(replaceVariables('{name} {name} {name}', variables)) |
24 | | - .to.eq('bob bob bob'); |
| 17 | + expect(replaceVariables('hello, my name is {name}, and i am {age} years old', variables)).to.eq('hello, my name is bob, and i am 32 years old'); |
| 18 | + expect(replaceVariables('{name} {name} {name}', variables)).to.eq('bob bob bob'); |
25 | 19 | }); |
26 | 20 | it('variables that are not defined do not get expanded', () => { |
27 | | - expect(replaceVariables('hello, my name is {name} and i work at {workplace}', variables)) |
28 | | - .to.eq('hello, my name is bob and i work at {workplace}'); |
29 | | - expect(replaceVariables('hello, my name is {Name}', variables)) |
30 | | - .to.eq('hello, my name is {Name}'); |
| 21 | + expect(replaceVariables('hello, my name is {name} and i work at {workplace}', variables)).to.eq( |
| 22 | + 'hello, my name is bob and i work at {workplace}' |
| 23 | + ); |
| 24 | + expect(replaceVariables('hello, my name is {Name}', variables)).to.eq('hello, my name is {Name}'); |
31 | 25 | }); |
32 | 26 |
|
33 | 27 | it('array access works', () => { |
34 | | - expect(replaceVariables('most favorite food is {favFoods[0]}, second favorite is {favFoods[1]}, and third is {favFoods[2]}', variables)) |
35 | | - .to.eq('most favorite food is takoyaki, second favorite is onigiri, and third is taiyaki'); |
36 | | - }); |
37 | | - it('index out of range', () => { |
| 28 | + expect(replaceVariables('most favorite food is {favFoods[0]}, second favorite is {favFoods[1]}, and third is {favFoods[2]}', variables)).to.eq( |
| 29 | + 'most favorite food is takoyaki, second favorite is onigiri, and third is taiyaki' |
| 30 | + ); |
38 | 31 | }); |
| 32 | + // it('index out of range', () => {}); |
39 | 33 |
|
40 | 34 | it('object access works', () => { |
41 | | - expect(replaceVariables('i work at {job.company} as a {job.position} on the {job.team} team', variables)) |
42 | | - .to.eq('i work at voiceflow as a software engineer on the creator team'); |
43 | | - }); |
44 | | - it('non-existent fields', () => { |
| 35 | + expect(replaceVariables('i work at {job.company} as a {job.position} on the {job.team} team', variables)).to.eq( |
| 36 | + 'i work at voiceflow as a software engineer on the creator team' |
| 37 | + ); |
45 | 38 | }); |
| 39 | + // it('non-existent fields', () => {}); |
46 | 40 |
|
47 | 41 | it('weird cases', () => { |
48 | 42 | const variables = { |
49 | 43 | '': 6969, |
50 | | - 'var': '{name}', |
51 | | - } |
52 | | - expect(replaceVariables('this is a blank variable {}', variables)) |
53 | | - .to.eq('this is a blank variable {}'); |
54 | | - expect(replaceVariables('{var}', variables)) |
55 | | - .to.eq('{name}'); |
| 44 | + var: '{name}', |
| 45 | + }; |
| 46 | + expect(replaceVariables('this is a blank variable {}', variables)).to.eq('this is a blank variable {}'); |
| 47 | + expect(replaceVariables('{var}', variables)).to.eq('{name}'); |
56 | 48 | }); |
57 | | - |
58 | 49 | }); |
59 | 50 | }); |
0 commit comments