JavaScript How should I test two nested immutable js data structures for deep equality?

Say I have the following nested immutable data structure:

import { Record, List } from 'immutable'

const foo = List([
        Record({
           id: 1,
           gameState: Record({})
         })
       ])

How would I test that two nested immutable js data structures are equal to each other?

test.js

import jest from 'jest'
import { Record, List } from 'immutable'

describe('test', () => {
    it('that foo equals expected', () => {
        const expected = List([
              Record({
                 id: 1,
                 gameState: Record({})
               })
             ])
        expect(foo).toEqual(expected)
    })
Answer:1

For most ImmutableJS types the test you've got would work fine. The problem is the way you're using Records. Unlike Map, List etc the constructorRecord(...) doesn't return a new object, it returns a constructor which can then be used to create new objects. From the docs (https://facebook.github.io/immutable-js/docs/#/Record):

[Record] Creates a new Class which produces Record instances. A record is similar to a JS object, but enforce a specific set of allowed string keys, and have default values.

If you want to user Record then you can write your test like this:

import { Record, List, is } from 'immutable'

describe('test', () => {
    it('that foo equals expected', () => {
        const gameState = Record({});
        const gameRecord = Record({
            id: 1,
            gameState: new gameState()
        });

        const foo = List([
            new gameRecord()
        ]);

        const expected = List([
            new gameRecord()
        ]);
        expect(foo.equals(expected)).toBe(true);
    })
});

Compare this to using a Map instead of a Record. The test below using jest's toEqual function passes as expected:

import { Map, List, is } from 'immutable'

describe('test', () => {
    it('that foo equals expected', () => {

        const foo = List([
            Map({
                id: 1,
                gameState: Map({})
            })
        ]);

        const expected = List([
            Map({
                id: 1,
                gameState: Map({})
            })
        ])
        expect(foo).toEqual(expected);
    })
});
Answer:2

Does anyone know if it's possible to populate a list of IDs for another model using waterline associations? I was trying to get the many-to-many association working but I don't think it applies here ...

Does anyone know if it's possible to populate a list of IDs for another model using waterline associations? I was trying to get the many-to-many association working but I don't think it applies here ...

  1. waterline populate association

I have a bar chart which use ChartJS that shows data. Based on the bar chart, I have the data: 15, 2, 0, 11. I can see all of these data in the bar, except 0. Is there a possibility to start the bar ...

I have a bar chart which use ChartJS that shows data. Based on the bar chart, I have the data: 15, 2, 0, 11. I can see all of these data in the bar, except 0. Is there a possibility to start the bar ...

  1. chart start with 0

I have a strange problem with ASP.NETmaster page and code behind. When Page.Header.DataBind() is called somehow all public method on my angular service are called. Here is my angular service: ...

I have a strange problem with ASP.NETmaster page and code behind. When Page.Header.DataBind() is called somehow all public method on my angular service are called. Here is my angular service: ...

  1. page.header.databind()
  2. page.header.databind failed to load viewstate
  3. page header databind in c#
  4. asp.net page.header.databind

function change(element) { document.getElementById('imageReplace').src = element; } function change_1() { document.getElementById('1').style.background = '#111'; document.getElementById('...

function change(element) { document.getElementById('imageReplace').src = element; } function change_1() { document.getElementById('1').style.background = '#111'; document.getElementById('...

  1. javascript takes long time load
  2. javascript window.open takes long time
  3. javascript function takes too long