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() }) })