From 96ea387d4db7360f283e8af7c6d5a4a3c94640a7 Mon Sep 17 00:00:00 2001 From: Cozy Pierre Date: Wed, 23 Feb 2022 16:31:12 +0100 Subject: [PATCH] fix(flags): Don't log when flags.enable called with empty array --- packages/cozy-flags/src/flag.js | 3 +++ packages/cozy-flags/src/index.spec.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/cozy-flags/src/flag.js b/packages/cozy-flags/src/flag.js index baa4d0e8b7..ddc52a649a 100644 --- a/packages/cozy-flags/src/flag.js +++ b/packages/cozy-flags/src/flag.js @@ -36,6 +36,9 @@ export const resetFlags = () => { export const enable = flagsToEnable => { let flagNameToValue if (Array.isArray(flagsToEnable)) { + if (flagsToEnable.length === 0) { + return + } // eslint-disable-next-line no-console console.log( 'flags.enable: Deprecation warning: prefer to use an object { flag1: true, flag2: true } instead of an array when using flags.enable' diff --git a/packages/cozy-flags/src/index.spec.js b/packages/cozy-flags/src/index.spec.js index a2cac99148..b43099eee6 100644 --- a/packages/cozy-flags/src/index.spec.js +++ b/packages/cozy-flags/src/index.spec.js @@ -16,9 +16,22 @@ describe('enable', () => { }) it('should enable the flags if the parameter is an array', () => { + const consoleSpy = jest.spyOn(console, 'log').mockImplementation() const flagsToEnable = ['hello', 'world', 'a'] flag.enable(flagsToEnable) expect(flag.list()).toEqual(['a', 'hello', 'world']) + + expect(consoleSpy).toHaveBeenCalledWith( + 'flags.enable: Deprecation warning: prefer to use an object { flag1: true, flag2: true } instead of an array when using flags.enable' + ) + consoleSpy.mockRestore() + }) + + it('should not log when called with empty array', () => { + const consoleSpy = jest.spyOn(console, 'log').mockImplementation() + flag([]) + expect(consoleSpy).not.toHaveBeenCalled() + consoleSpy.mockRestore() }) })