Skip to content

Commit

Permalink
welldone-software#11 return the same instance in makeArray when the…
Browse files Browse the repository at this point in the history
… argument is an array
  • Loading branch information
cvetanov committed Feb 12, 2018
1 parent c1819bd commit 363edbd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/redux-toolbelt-immutable-helpers/src/makeArray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import concat from 'lodash.concat'
import isArray from 'lodash.isarray'

export default function makeArray(arrayOrObject) {
// Converts the object into array (if it's not an array already)
return concat(arrayOrObject)
return isArray(arrayOrObject) ? arrayOrObject : concat(arrayOrObject)
}
4 changes: 2 additions & 2 deletions packages/redux-toolbelt-immutable-helpers/test/makeArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ test('makeArray creates array from object', () => {
expect(result).toEqual([obj])
})

test('makeArray copies the provided array to a new one', () => {
test('makeArray returns the same array when provided an array', () => {
const arr = Object.freeze(
[{id: 1, val: 5}, {id: 2, val: 6}]
)

const result = makeArray(arr)

expect(result).toEqual(arr)
expect(result).toBe(arr)
})

0 comments on commit 363edbd

Please sign in to comment.