-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
30 lines (22 loc) · 950 Bytes
/
index.test.js
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
const replaceVars = require('./index');
test('check invalid input', () => {
expect(() => replaceVars(undefined, {})).toThrow('Non-string input given');
});
test('check invalid variables', () => {
expect(() => replaceVars('', '')).toThrow('Variable configuration is not an object');
});
test('replace single variable', () => {
expect(replaceVars('{input}', { input: 'hello' })).toBe('hello');
});
test('replace multiple instances of variable', () => {
expect(replaceVars('he{letter}{letter}o', { letter: 'l' })).toBe('hello');
});
test('replace multiple different variables', () => {
expect(replaceVars('{one}{two}', { one: 'hel', two: 'lo' })).toBe('hello');
});
test('ignore unspecified variables', () => {
expect(replaceVars('{one} {two}', { one: 'hello' })).toBe('hello {two}');
});
test('ignore additional variables', () => {
expect(replaceVars('hello there', { general: 'Kenobi!' })).toBe('hello there');
});