question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object literals: Compared values have no visual difference.

See original GitHub issue

image

System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Binaries:
    npm: 5.8.0 - C:\Users\Owner\AppData\Roaming\npm\npm.CMD

I am on jest@22.4.3.

The two objects are the same. I’ve done some research, and it seems that the Compared values have no visual difference. occurs when there is an anonymous function in question. This is not the case.

Here’s the code:

const stripData = obj => obj.data
const assign = child => parent => Object.assign(parent, child)
const arrAssign = (arr, k) => data => data.map((d, i) => assign({[k]: d})(arr[i]))

/* function being tested */
const insertAndPair = (obj, key1, key2) => compose(
  d => assign({ [key1]: arrAssign(obj.slice(-1)[0][key1], key2)(d) })(obj.slice(-1)),
  stripData
)

Here’s the test:

it('given an array and key then an object, assigns the first'
  + ' element in the array to the object with the given key', () => {

    const arr = [{
      vals: [
        { x: [], y: 'hello'},
        { x: [], y: 'hey'}
      ]
    }]

    expect(
      insertAndPair(arr, 'vals', 'x')({data: [1, 2]})
    ).toEqual([ { vals: [
      { x: 1, y: 'hello' },
      { x: 2, y: 'hey' }
    ] } ])
  })

Pardon my convoluted code, haha!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

30reactions
Kaelinatorcommented, Apr 15, 2018

Wrapping them both in JSON.stringify passes the test, but I find this to be a workaround rather than a fix.

9reactions
Yorkshiremancommented, Oct 3, 2018

@SimenB how about “Compared values have no visual difference but may have different properties.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Test "Compared values have no visual difference."
The test fails with the error Compared values have no visual difference . To understand what is going on I recommend to log...
Read more >
Jest Test "Compared values have no visual difference."-Reactjs
The test fails with the error Compared values have no visual difference . To understand what is going on I recommend to log...
Read more >
Expect - Jest
The expect function is used every time you want to test a value. ... It calls Object.is to compare values, which is even...
Read more >
JavaScript Objects - W3Schools
All JavaScript values, except primitives, are objects. JavaScript Primitives. A primitive value is a value that has no properties or methods.
Read more >
Python '!=' Is Not 'is not': Comparing Objects in Python
When to use equality and identity operators to compare objects; What these Python operators do under the hood; Why using is and is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found