Esm: lodash merge in Jest realm nulls out existing properties

Created on 20 Aug 2018  路  7Comments  路  Source: standard-things/esm

esm options in package.json

  "esm": {
    "cjs": true
  },

Use lodash merge on these two objects in an esmed package somewhere

import { merge } from 'lodash'

const a = {
  "test": {
    "prop1": "property first",
    "prop2": {
      "prop3": "property second.third"
    }
  }
}

const b = {
  "test": {
    "prop2": {
      "prop3": "property second.third.override"
    }
  }
}

console.log(merge(a, b))

Expected behavior (in any realm including Jest)

{
  "test": {
    "prop1": "property first",
    "prop2": {
      "prop3": "property second.third.override"
    }
  }
}

Actual behavior (in Jest realm only)

 {
  "test": { // looses prop1
    "prop2": {
      "prop3": "property second.third.override"
    }
  }
}

version

[email protected]

bug

Most helpful comment

you probably fixed it already 馃槂 but Ctor instanceof Ctor in isPlainObject is false.

I did by the time you commented and I root caused it to Ctor instanceof Ctor too 馃樃

All 7 comments

Hi @charandas!

The cjs option is true by default so likely unneeded. Could you create a small repro repo for me to look at?

@jdalton here is the repro - thanks for looking at it.

@jdalton i wonder if this one will have far reaching consequences. sequelize for one thing in jest realm is behaving weird, it no longer is recognizing my existing primary keys and trying to stamp a default id column which does not exist on my tables.

I have been eagerly waiting on jest support but did not know it would lead you or me through a rabbithole.

If you want me to get off your back, simply ask. I may have to move to mocha if jest support remains unsurmountable in the near future. When esm used to be @std/esm, my tests with jest used to run fine. Not sure why - this was pre-stable versions, and with both typescript and esm moving on, I have grappled with the setup I created last year.

was just curious and debugging this.

@jdalton you probably fixed it already 馃槂 but Ctor instanceof Ctor in isPlainObject is false.

you probably fixed it already 馃槂 but Ctor instanceof Ctor in isPlainObject is false.

I did by the time you commented and I root caused it to Ctor instanceof Ctor too 馃樃

@jdalton just confirming that all my sequelize issues in jest have been resolved by 3.0.80. At last, need it to be published to npm now.

v3.0.80 is released :tada:

Was this page helpful?
0 / 5 - 0 ratings