chaId
Id equality assertions for chai.
Ids come in lots of flavors. Sometimes they're strings, sometimes objects. Sometimes you'll find them at .id
, other times at ._id
. ChaId lets you test for equality by comparing string representations of ids, with minimal fretting about initial representation or location:
_id: 'foo'shouldhaveid'foo''foo'shouldidid: 'foo'id: 'foo' bar: 2shouldhavesameidid: 'foo' baz: 3_id: 'foo'shouldnothavesameid_id: 'bar'_id: 'foo'shouldhavesameidid: { return 'foo'})_id: 'foo'shouldhaveid'foo'
You can also compare lists of objects by id:
id:'a' id:'b'shouldhaveids 'a' 'b''a' 'b'shouldbeids 'a' 'b'id:'a' id:'b'shouldhavesameids id:'a' id:'b'id:'a' id:'b'shouldnothavesameids id:'b' id:'a'
By default, order matters. To ignore order, chain unordered
:
id:'a' id:'b'shouldhavesameunorderedids id:'b' id:'a'
You can test for a subset of ids by chaining include
or contain
:
id:'a' id:'b'shouldincludesameids id:'a'
Works well with MongoDB ObjectIds:
docshouldhaveiddocshouldhavesameidotherDocshouldiddoc
Installation
This is a plugin for the Chai Assertion Library. Install via npm.
npm install chaid
Plugin
Use this plugin as you would all other Chai plugins.
var chai = chaid = ; chai;