Also test the two options while we're at it

pull/21833/head
David Baker 2018-10-11 21:04:50 +01:00
parent 53e13be047
commit a58de9e189
1 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,11 @@ const OBJECTS = [
{ name: "Victoria", nick: "Posh" },
];
const NONWORDOBJECTS = [
{ name: "B.O.B" },
{ name: "bob" },
];
describe('QueryMatcher', function() {
it('Returns results by key', function() {
const qm = new QueryMatcher(OBJECTS, {keys: ["name"]});
@ -133,4 +138,38 @@ describe('QueryMatcher', function() {
expect(results[1].name).toBe('Mel C');
expect(results[2].name).toBe('Emma');
});
it('Matches words only by default', function() {
const qm = new QueryMatcher(NONWORDOBJECTS, { keys: ["name"] });
const results = qm.match('bob');
expect(results.length).toBe(2);
expect(results[0].name).toBe('B.O.B');
expect(results[1].name).toBe('bob');
});
it('Matches all chars with words-only off', function() {
const qm = new QueryMatcher(NONWORDOBJECTS, {
keys: ["name"],
shouldMatchWordsOnly: false,
});
const results = qm.match('bob');
expect(results.length).toBe(1);
expect(results[0].name).toBe('bob');
});
it('Matches only by prefix with shouldMatchPrefix on', function() {
const qm = new QueryMatcher([
{name: "Victoria"},
{name: "Tori"},
], {
keys: ["name"],
shouldMatchPrefix: true,
});
const results = qm.match('tori');
expect(results.length).toBe(1);
expect(results[0].name).toBe('Tori');
});
});