-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat.test.js
More file actions
22 lines (18 loc) · 927 Bytes
/
format.test.js
File metadata and controls
22 lines (18 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const Format = require('../src/format');
describe('Format', () => {
it('should format a string with placeholders', () => {
const formatInstance = new Format('Hello, {0}! How are you, {1}?', 'Alice', 'Bob');
expect(formatInstance.execute()).toBe('Hello, Alice! How are you, Bob?');
});
it('should handle placeholders with duplicate indices', () => {
const formatInstance = new Format('My name is {0}, not {0}!', 'Alice');
expect(formatInstance.execute()).toBe('My name is Alice, not Alice!');
});
it('should handle placeholders with missing arguments', () => {
const formatInstance = new Format('Hello, {0}!', 'Alice', 'Bob');
expect(formatInstance.execute()).toBe('Hello, Alice!');
});
it('should handle non-string format strings', () => {
expect(() => new Format(123, 'Alice')).toThrowError('Format string must be a string');
});
});