blob: c4e0d13387a3808e0901063da171361d4fc19044 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
const { describe, expect, it, vi } = await import('vitest');
const { allLocales, SimpleFaker } = require('../dist/index.js');
describe('require (cjs)', () => {
describe.each(
Object.keys(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
allLocales
)
)('locale imports', (locale) => {
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
const { faker } = require(`../dist/locale/${locale}.js`);
expect(faker).toBeDefined();
expect(faker.string.alpha()).toBeTypeOf('string');
expect(faker.definitions.metadata.title).toBe(
allLocales[locale].metadata?.title
);
});
});
describe('simpleFaker', () => {
it('should not log anything on startup', () => {
const spies = Object.keys(console)
.filter(
(key) =>
// @ts-expect-error: cts cant use `as keyof typeof console`
typeof console[key] === 'function'
)
.map((methodName) =>
vi.spyOn(
console,
// @ts-expect-error: cts cant use `as keyof typeof console`
methodName
)
);
expect(require('..').simpleFaker).toBeDefined();
expect(new SimpleFaker()).toBeDefined();
for (const spy of spies) {
expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
}
});
});
});
|