-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (33 loc) · 1.28 KB
/
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
30
31
32
33
34
35
36
37
38
import test from 'ava';
import hyphenSanitizer from './index.js';
test('Replace hyphens with spaces by default', t => {
const originalString = 'This-is-a-sample-string';
const expectedString = 'This is a sample string';
t.is(hyphenSanitizer(originalString), expectedString);
});
test('Replace hyphens with a custom string', t => {
const originalString = 'This-is-a-sample-string';
const expectedString = 'This_is_a_sample_string';
const customReplacement = '_';
t.is(hyphenSanitizer(originalString, customReplacement), expectedString);
});
test('Return empty string for empty input string', t => {
const originalString = '';
const expectedString = '';
t.is(hyphenSanitizer(originalString), expectedString);
});
test('Throw error for non-string input', t => {
const invalidInput = 123; // Non-string input
const error = t.throws(() => {
hyphenSanitizer(invalidInput);
}, {instanceOf: TypeError});
t.is(error.message, 'Input value must be a string.');
});
test('Throw error for non-string replacement', t => {
const originalString = 'This-is-a-sample-string';
const invalidReplacement = 123; // Non-string replacement
const error = t.throws(() => {
hyphenSanitizer(originalString, invalidReplacement);
}, {instanceOf: TypeError});
t.is(error.message, 'Replacement must be a string.');
});