diff options
| author | ST-DDT <[email protected]> | 2022-02-10 23:52:14 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-10 23:52:14 +0100 |
| commit | 14df7d3f70b54c4a153f5dcf111ef90575bbbe9e (patch) | |
| tree | 2e7bc398eeb0c6312218f6ffe5d44876d7ab3bc5 /test | |
| parent | 2a4f835db2a9c324c4d4a65a69c9469eaf9572de (diff) | |
| download | faker-14df7d3f70b54c4a153f5dcf111ef90575bbbe9e.tar.xz faker-14df7d3f70b54c4a153f5dcf111ef90575bbbe9e.zip | |
fix: fix unique method types (#457)
Diffstat (limited to 'test')
| -rw-r--r-- | test/unique.spec.ts | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/test/unique.spec.ts b/test/unique.spec.ts index 04215ea1..86debefe 100644 --- a/test/unique.spec.ts +++ b/test/unique.spec.ts @@ -5,19 +5,25 @@ const seededRuns = [ { seed: 42, expectations: { - withMethod: 'Test-188', + withCustomMethod: 'Test-188', + withNumberMethod: 37454, + withNumberMethodAndArgs: 19, }, }, { seed: 1337, expectations: { - withMethod: 'Test-132', + withCustomMethod: 'Test-132', + withNumberMethod: 26202, + withNumberMethodAndArgs: 13, }, }, { seed: 1211, expectations: { - withMethod: 'Test-465', + withCustomMethod: 'Test-465', + withNumberMethod: 92852, + withNumberMethodAndArgs: 47, }, }, ]; @@ -29,7 +35,7 @@ const MOCK_ARRAY = Array.from( (_, index) => `Test-${index + 1}` ); -function method(prefix: string = ''): string { +function customMethod(prefix: string = ''): string { const element = faker.random.arrayElement(MOCK_ARRAY); return `${prefix}${element}`; } @@ -41,20 +47,34 @@ describe('unique', () => { for (const { seed, expectations } of seededRuns) { describe(`seed: ${seed}`, () => { - it(`unique(method)`, () => { + it(`unique(customMethod)`, () => { faker.seed(seed); - const actual = faker.unique(method); - expect(actual).toEqual(expectations.withMethod); + const actual = faker.unique(customMethod); + expect(actual).toEqual(expectations.withCustomMethod); }); - it(`unique(method, args)`, () => { + it(`unique(customMethod, args)`, () => { faker.seed(seed); const prefix = 'prefix-1-'; - const actual = faker.unique(method, [prefix]); - expect(actual).toEqual(prefix + expectations.withMethod); + const actual = faker.unique(customMethod, [prefix]); + expect(actual).toEqual(prefix + expectations.withCustomMethod); + }); + + it(`unique(() => number)`, () => { + faker.seed(seed); + + const actual = faker.unique(faker.datatype.number); + expect(actual).toEqual(expectations.withNumberMethod); + }); + + it(`unique(() => number), args)`, () => { + faker.seed(seed); + + const actual = faker.unique(faker.datatype.number, [50]); + expect(actual).toEqual(expectations.withNumberMethodAndArgs); }); }); } |
