aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-04-04 16:47:03 +0200
committerGitHub <[email protected]>2022-04-04 14:47:03 +0000
commit8b545b4e72e0d00f93d51f8de876103bedebff03 (patch)
treea9488736462c05ca887f9f2432cf7c69396b6c80 /test
parent9e03bcff3aaad13afbfae99fb1df046c2f227c2c (diff)
downloadfaker-8b545b4e72e0d00f93d51f8de876103bedebff03.tar.xz
faker-8b545b4e72e0d00f93d51f8de876103bedebff03.zip
chore: fix mustache type warning and add some tests (#753)
Diffstat (limited to 'test')
-rw-r--r--test/helpers.spec.ts49
1 files changed, 44 insertions, 5 deletions
diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts
index 0be83f98..cf817ae5 100644
--- a/test/helpers.spec.ts
+++ b/test/helpers.spec.ts
@@ -724,11 +724,50 @@ describe('helpers', () => {
});
describe('mustache()', () => {
- it('returns empty string with no arguments', () => {
- expect(
- // @ts-expect-error
- faker.helpers.mustache()
- ).toBe('');
+ it('returns empty string with no template input', () => {
+ expect(faker.helpers.mustache(undefined, {})).toBe('');
+ });
+
+ it('returns empty string with empty template input', () => {
+ expect(faker.helpers.mustache('', {})).toBe('');
+ });
+
+ it('supports string replace values', () => {
+ const actual = faker.helpers.mustache('1{{value}}3', { value: '2' });
+
+ expect(actual).toBe('123');
+ });
+
+ it('supports function replace values faker values', () => {
+ const actual = faker.helpers.mustache('1{{value}}3', {
+ value: faker.datatype.string(2),
+ });
+
+ expect(actual).toHaveLength(4);
+ });
+
+ it('supports function replace values faker function', () => {
+ const actual = faker.helpers.mustache('1{{value}}3', {
+ value: () => faker.datatype.string(3),
+ });
+
+ expect(actual).toHaveLength(5);
+ });
+
+ it('supports function replace values no args', () => {
+ const actual = faker.helpers.mustache('1{{value}}3', {
+ value: () => '7',
+ });
+
+ expect(actual).toBe('173');
+ });
+
+ it('supports function replace values with args', () => {
+ const actual = faker.helpers.mustache('1{{value}}3', {
+ value: (key) => String(key.length),
+ });
+
+ expect(actual).toBe('193');
});
});