Immutable-js: Invalid keypath error does not give sufficient feedback

Created on 20 Oct 2015  路  3Comments  路  Source: immutable-js/immutable-js

This mocha test describes my issue:

function closeInstance(processState, name) {
  return processState.deleteIn(['processes', name, 'opened'])
}

it('closeInstance function removes the opened key from the passed process', () => {
  const processState = Map({
    processes: {
      p1: {
        id:     1,
        opened: 'instance_1'
      },
      p2: {
        id:     2,
        opened: 'instance_43'
      }
    }
  })
  const nextState = closeInstance(processState, 'p1')
  const expected = {
    processes: {
      p1: {
        id: 1
      },
      p2: {
        id:     2,
        opened: 'instance_1'
      }
    }
  }
  expect(nextState.toJS()).to.deep.equal(expected)
})

Running this test produces the invalid keypath error in the closeInstance method

Most helpful comment

I believe the issue here is that Map does not deeply convert the argument.

processState.get('processes') returns a vanilla JS object, so the getIn call in closeInstance returns undefined.

Try using Immutable.fromJS to deeply convert the object.

All 3 comments

I believe the issue here is that Map does not deeply convert the argument.

processState.get('processes') returns a vanilla JS object, so the getIn call in closeInstance returns undefined.

Try using Immutable.fromJS to deeply convert the object.

That fixed my issue, thank you. :+1:

Merging into #635

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbonta picture jbonta  路  3Comments

jshthornton picture jshthornton  路  3Comments

Haroenv picture Haroenv  路  3Comments

kopax picture kopax  路  3Comments

Delapouite picture Delapouite  路  3Comments