Skip to content

Commit

Permalink
Merge pull request #144 from albe/undefined-matcher
Browse files Browse the repository at this point in the history
Fix matcher with undefined property checks
  • Loading branch information
albe committed Feb 9, 2021
2 parents bb2ab76 + 4c88c01 commit d9c28c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function matches(document, matcher) {
if (!matches(document[prop], matcher[prop])) {
return false;
}
} else if (document[prop] !== matcher[prop]) {
} else if (typeof matcher[prop] !== 'undefined' && document[prop] !== matcher[prop]) {
return false;
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/Storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,19 @@ describe('Storage', function() {
expect(index.length).to.be(1);
});

it('indexes documents by property object matcher ignoring undefined properties', function(done) {
storage = createStorage();
storage.open();
storage.write({type: 'Bar', other: '1'});
storage.write({type: 'Foo', other: '2'});
storage.write({type: 'Baz', other: '3'}, () => {
let index = storage.ensureIndex('foo', {type: 'Foo', other: undefined});

expect(index.length).to.be(1);
done();
});
});

it('reopens existing indexes', function() {
storage = createStorage();
storage.open();
Expand Down

0 comments on commit d9c28c0

Please sign in to comment.