aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/matcher/options.test.ts20
-rw-r--r--src/matcher/options.ts5
2 files changed, 23 insertions, 2 deletions
diff --git a/src/matcher/options.test.ts b/src/matcher/options.test.ts
index 058ef9e..39c4b3e 100644
--- a/src/matcher/options.test.ts
+++ b/src/matcher/options.test.ts
@@ -75,7 +75,7 @@ describe('Object Matching:', () => {
let matchee = {
a: 432,
b: {
- ba: "barracus",
+ ba: "baracus",
bb: new Function(),
},
c: true,
@@ -83,5 +83,23 @@ describe('Object Matching:', () => {
};
options.match(template, matchee).should.be.true;
});
+ it('accepts literal matches', () => {
+ let template = {
+ a: "literal"
+ };
+ let matchee = {
+ a: "literal"
+ };
+ options.match(template, matchee).should.be.true;
+ });
+ it('rejects incorrect literal matches', () => {
+ let template = {
+ g: 99
+ };
+ let matchee = {
+ g: 80
+ };
+ options.match(template, matchee).should.be.false;
+ });
});
});
diff --git a/src/matcher/options.ts b/src/matcher/options.ts
index e93c2fd..2e65105 100644
--- a/src/matcher/options.ts
+++ b/src/matcher/options.ts
@@ -9,9 +9,12 @@ export function match(template: Object, value?: Object) {
let f;
if (types.object(template[k])) {
f = match(template[k]);
- } else {
+ } else if (types.function(template[k])) {
f = template[k];
+ } else {
+ f = (v) => v === template[k];
}
+
if (!f(value[k])) {
return false;
}