aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-03-28 19:28:50 +0200
committerGitHub <[email protected]>2022-03-28 17:28:50 +0000
commit8d1aefbda070265909cedb07af564ea143be74a7 (patch)
tree62fc9556a59d01ac14ecc05debd8d068845b701e /test
parentd2fc1e6b5ba55242d16b9b8a1e9f42c7b24957b0 (diff)
downloadfaker-8d1aefbda070265909cedb07af564ea143be74a7.tar.xz
faker-8d1aefbda070265909cedb07af564ea143be74a7.zip
fix: fake behavior with special replacement patterns (#688)
Diffstat (limited to 'test')
-rw-r--r--test/fake.spec.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/fake.spec.ts b/test/fake.spec.ts
index a78940ea..530d09d2 100644
--- a/test/fake.spec.ts
+++ b/test/fake.spec.ts
@@ -50,5 +50,39 @@ describe('fake', () => {
it('should be able to return empty strings', () => {
expect(faker.fake('{{helpers.repeatString}}')).toBe('');
});
+
+ it('should be able to handle only {{ brackets', () => {
+ expect(faker.fake('{{hello')).toBe('{{hello');
+ expect(faker.fake('hello{{')).toBe('hello{{');
+ });
+
+ it('should be able to handle only }} brackets', () => {
+ expect(faker.fake('hello}}')).toBe('hello}}');
+ expect(faker.fake('}}hello')).toBe('}}hello');
+ });
+
+ it('should be able to handle reverted brackets', () => {
+ expect(faker.fake('}}hello{{')).toBe('}}hello{{');
+ });
+
+ it('should be able to handle random }} brackets', () => {
+ expect(faker.fake('}}hello{{random.alpha}}')).toMatch(/^}}hello[a-z]$/);
+ });
+
+ it('should be able to handle connected brackets', () => {
+ expect(faker.fake('{{{random.alpha}}}')).toMatch(/^{[a-z]}$/);
+ });
+
+ it('should be able to handle empty brackets', () => {
+ expect(faker.fake('{{}}')).toBe('{{}}');
+ });
+
+ it('should be able to handle special replacement patterns', () => {
+ (faker.random as any).special = () => '$&';
+
+ expect(faker.fake('{{random.special}}')).toBe('$&');
+
+ delete (faker.random as any).special;
+ });
});
});