wankdanker / node-object-mapper

Copy properties from one object to another.
MIT License
276 stars 73 forks source link

transformer is being call with null when default exists #71

Closed sylvainlegault closed 4 years ago

sylvainlegault commented 4 years ago

When there is a default function and no value the tansform function should not be call.

The following test works in v5 but fails in v6 with a runtime exception since the transform function is being call with a null value Cannot read property 'map' of null

const mapper = require('object-mapper')
const format = sizes => sizes.map(data => data)
const MAPPING = {
  mySizes: [
    {
      key: 'sizes',
      transform: format,
      default: () => []
    }
  ]
}
describe('Mapping array', () => {
  it('should not fail when not defined', () => {
    const result = mapper({}, MAPPING)
    expect(result).toEqual({sizes: []})
  })
})