|
1 | 1 | import test from 'ava';
|
2 | 2 | import replaceString from './';
|
3 | 3 |
|
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('')); |
7 | 7 | });
|
8 | 8 |
|
9 | 9 | test('Returns an array', t => {
|
@@ -120,3 +120,24 @@ test('Allows empty strings within results', t => {
|
120 | 120 | '',
|
121 | 121 | ]);
|
122 | 122 | });
|
| 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