Skip to content

Commit 301a6d2

Browse files
authored
fix: fake is unable to return empty strings (#347)
1 parent 9ce1551 commit 301a6d2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/fake.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export class Fake {
116116
// replace the found tag with the returned fake value
117117
res = str.replace('{{' + token + '}}', result);
118118

119+
if (res === '') {
120+
return '';
121+
}
122+
119123
// return the response recursively until we are done finding all tags
120124
return this.fake(res);
121125
}

test/fake.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ describe('fake', () => {
4646
Error('Invalid method: address.foo')
4747
);
4848
});
49+
50+
it('should be able to return empty strings', () => {
51+
expect(faker.fake('{{helpers.repeatString}}')).toBe('');
52+
});
4953
});
5054
});

0 commit comments

Comments
 (0)