From a28b5deab9079c567b7eb8a1917c661cadd35849 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 21 Apr 2022 20:33:59 +0200 Subject: [PATCH] fix: dont log deprecations on startup (#857) --- src/unique.ts | 7 ++++++- test/faker.spec.ts | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/unique.ts b/src/unique.ts index ff8698e695d..f59a8ef23ea 100644 --- a/src/unique.ts +++ b/src/unique.ts @@ -83,7 +83,12 @@ export class Unique { constructor() { // Bind `this` so namespaced is working correctly for (const name of Object.getOwnPropertyNames(Unique.prototype)) { - if (name === 'constructor' || typeof this[name] !== 'function') { + if ( + name === 'constructor' || + name === 'maxTime' || + name === 'maxRetries' || + typeof this[name] !== 'function' + ) { continue; } this[name] = this[name].bind(this); diff --git a/test/faker.spec.ts b/test/faker.spec.ts index d8ca61c8094..7417121026e 100644 --- a/test/faker.spec.ts +++ b/test/faker.spec.ts @@ -1,4 +1,5 @@ -import { beforeEach, describe, expect, it } from 'vitest'; +import type { SpyInstance } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { faker, Faker } from '../src'; import { FakerError } from '../src/errors/faker-error'; @@ -31,6 +32,24 @@ describe('faker', () => { ); }); + it('should not log anything on startup', () => { + const spies: Array = Object.keys(console) + .filter((key) => typeof console[key] === 'function') + .map((methodName) => + vi.spyOn(console, methodName as keyof typeof console) + ); + + // eslint-disable-next-line @typescript-eslint/no-var-requires + require('..').faker; + + new Faker({ locales: { en: { title: '' } } }); + + for (const spy of spies) { + expect(spy).not.toHaveBeenCalled(); + spy.mockRestore(); + } + }); + describe('definitions', () => { describe('title', () => { it.each(Object.keys(faker.locales))('title (%s)', (locale) => {