You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect that a deep.include of an array of objects compares the contained objects via deep.include and not via deep.equal.
aka. expect([{x:1,y:2}]).deep.include([{x:1}]) behaves like expect({x:1,y:2}).deep.include({x:1})
version
chai 4.3.6
expected
1
2
3
actual
1
/home/mknj/js/chai/node_modules/chai/lib/chai/assertion.js:152
throw new AssertionError(
^
AssertionError: expected [ { d: 1, e: 2 } ] to deep include [ { d: 1 } ]
at Object.<anonymous> (/home/mknj/js/chai/test.js:13:28)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
showDiff: false,
actual: [ { d: 1, e: 2 } ],
expected: undefined,
operator: 'strictEqual'
}
example code with workaround using lodash
constexpect=require("chai").expectconst_=require("lodash")consta={b:{c:[{d:1}]}}constresult={a:1,b:{c:[{d:1,e:2}]}}// workaround for 3expect(result).to.deep.equal(_.merge(result,a))// ok (object include)expect(result.b.c[0]).to.deep.include(a.b.c[0])console.log(1)// bad (array of object include)expect(result.b.c).to.deep.include(a.b.c)console.log(2)// bad (object..array of object include)expect(result).to.deep.include(a)console.log(3)
The text was updated successfully, but these errors were encountered:
I have an API with a request object, that is similar to the response object. The response object does contain some additional information including timestamps.
To verify that the original elements are in the response i would like to do a expect(response).to.deep.INCLUDE(request).
After that i want to do a expect(response).to.deep.INCLUDE([{some_important_fields}])
to check additional fields excluding i.e. timestamps.
I understand for simple cases that include/contains behave differently for arrays and objects.
However deep comparing objects containing arrays of objects leads to strange situations.
i.e. object_include is applied recursively to the main object, but not to the objects in an array.
summary
I would expect that a deep.include of an array of objects compares the contained objects via deep.include and not via deep.equal.
aka.
expect([{x:1,y:2}]).deep.include([{x:1}])
behaves likeexpect({x:1,y:2}).deep.include({x:1})
version
chai 4.3.6
expected
actual
example code with workaround using lodash
The text was updated successfully, but these errors were encountered: