Skip to content

Commit 751a9e6

Browse files
committed
Add tests for empty string as first element of input. Relates to #4
1 parent 75d5f3c commit 751a9e6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava';
22
import replaceString from './';
33

4-
test('Throws if not given a non-empty string', t => {
5-
t.throws(() => replaceString());
6-
t.throws(() => replaceString(''));
4+
test("Doesn't throw if not given invalid input", t => {
5+
t.notThrows(() => replaceString());
6+
t.notThrows(() => replaceString(''));
77
});
88

99
test('Returns an array', t => {
@@ -120,3 +120,24 @@ test('Allows empty strings within results', t => {
120120
'',
121121
]);
122122
});
123+
124+
test('Will not through if first element of input is empty string', t => {
125+
const string = 'http://a_photo.jpg some string';
126+
const replacedContent = replaceString(string, /(http?:\/\/.*\.(?:png|jpg))/g, match => {
127+
return { key: 'image', match };
128+
});
129+
130+
t.deepEqual(replacedContent, [
131+
'',
132+
{ key: 'image', match: 'http://a_photo.jpg' },
133+
' some string',
134+
]);
135+
136+
// This replacement would not actually give a new result from above, but it is
137+
// simply to test that passing in an empty string as the first arg is OK
138+
t.notThrows(() => {
139+
replaceString(replacedContent, /@(\w+)/g, match => {
140+
return { key: 'text', match };
141+
});
142+
});
143+
});

0 commit comments

Comments
 (0)