-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.test.js
More file actions
52 lines (43 loc) · 1.97 KB
/
Copy pathutils.test.js
File metadata and controls
52 lines (43 loc) · 1.97 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
import { isEmptyString, interpolate } from '../utils';
describe('isEmptyString', () => {
it('treats missing values (null/undefined) as empty', () => {
expect(isEmptyString(undefined)).toBe(true);
expect(isEmptyString(null)).toBe(true);
});
it('treats empty and whitespace-only strings as empty', () => {
expect(isEmptyString('')).toBe(true);
expect(isEmptyString(' ')).toBe(true);
});
it('treats a non-empty string as not empty', () => {
expect(isEmptyString('Finish Now')).toBe(false);
expect(isEmptyString(' x ')).toBe(false);
});
});
describe('interpolate', () => {
it('replaces every occurrence of a {token} with its value', () => {
expect(interpolate('click the "{button}" button', { button: 'Finish Now' }))
.toBe('click the "Finish Now" button');
expect(interpolate('{a} and {a}', { a: 'x' })).toBe('x and x');
});
it('replaces multiple distinct tokens', () => {
expect(interpolate('assigned to {attendee}, complete {adv} details', { attendee: 'you', adv: 'your' }))
.toBe('assigned to you, complete your details');
});
it('leaves unknown tokens untouched', () => {
expect(interpolate('hello {name}', { button: 'x' })).toBe('hello {name}');
});
it('returns a non-string template unchanged', () => {
expect(interpolate(undefined, { a: '1' })).toBe(undefined);
});
it('does not substitute into a value it just inserted', () => {
// Values come from marketing overrides, so one that happens to contain
// a token must land as written rather than be expanded in turn.
expect(interpolate('{attendee} pays', { attendee: '{button}', button: 'Finish Now' }))
.toBe('{button} pays');
});
it('is unaffected by the shared regex across calls', () => {
const call = () => interpolate('{a} {a}', { a: 'x' });
expect(call()).toBe('x x');
expect(call()).toBe('x x');
});
});