Skip to content

Commit

Permalink
feat: extend error message details (#112)
Browse files Browse the repository at this point in the history
* feat: extend error message details

* chore: fix tests

Co-authored-by: Meghea Iulian <[email protected]>
  • Loading branch information
dotpointer and megheaiulian authored Mar 17, 2020
1 parent 083a7a1 commit 602ac7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cosmoz-data-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,11 @@ class CosmozDataNav extends translatable(mixinBehaviors([IronResizableBehavior],

if (matches.length === 0) {
// eslint-disable-next-line no-console
console.warn('trying to replace an item that is not in the list', id, item);
console.warn('List item replacement failed, no matching idPath', this.idPath, 'with id', id, 'in the item list', items, 'to replace with item', item);
return;
} else if (matches.length > 1) {
// eslint-disable-next-line no-console
console.warn('found multiple items with same id');
console.warn('Multiple replaceable items matches idPath', this.idPath, 'with id', id, 'in the item list', items, 'to replace with item', item);
}

this._cache[id] = Object.assign({}, item);
Expand Down
18 changes: 16 additions & 2 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@
data = { id: 0 },
cache = nav._cache;
nav.setItemById('0', data);
assert.isTrue(warnSpy.calledWithExactly('found multiple items with same id'), true);
sinon.assert.calledWith(warnSpy,
'Multiple replaceable items matches idPath',
'id',
'with id',
'0',
'in the item list', nav.items,
'to replace with item', {id: 0});
assert.equal(cache['0'].id, data.id);
assert.equal(nav.items[0].id, data.id);
assert.equal(nav.items[1].id, data.id);
Expand Down Expand Up @@ -271,7 +277,15 @@
const warnSpy = sinon.spy(console, 'warn'),
data = { id: 23 };
nav.setItemById('23', data);
assert.isTrue(warnSpy.calledWithExactly('trying to replace an item that is not in the list', '23', data), true);
sinon.assert.calledWith(warnSpy,
'List item replacement failed, no matching idPath',
'id',
'with id',
'23',
'in the item list',
nav.items,
'to replace with item',
data);
warnSpy.restore();
});

Expand Down

0 comments on commit 602ac7c

Please sign in to comment.