Skip to content

Commit

Permalink
fix(flags): Don't log when flags.enable called with empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
trollepierre committed Mar 1, 2022
1 parent 66321ed commit 96ea387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/cozy-flags/src/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions packages/cozy-flags/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit 96ea387

Please sign in to comment.