match-json
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -71,3 +71,3 @@ "use strict"; | ||
return Object.keys(expected).every((key) => | ||
matchCore(object[key], expected[key], partialMode) | ||
object[key] ? matchCore(object[key], expected[key], partialMode) : false | ||
); | ||
@@ -96,2 +96,8 @@ } | ||
break; | ||
case Object: | ||
result = type(value) === "object"; | ||
break; | ||
case Array: | ||
result = type(value) === "array"; | ||
break; | ||
default: | ||
@@ -98,0 +104,0 @@ result = func.call(null, value); |
{ | ||
"name": "match-json", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "A light assertion library built with JSON APIs in mind.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -28,5 +28,6 @@ "use strict"; | ||
it("match:boolean_true", (t) => expect(match(false, false)).to.equal(true)); | ||
it("match:boolean_true", (t) => expect(match(true, true)).to.equal(true)); | ||
it("match:undefined", (t) => expect(match(undefined, undefined)).to.equal(true)); | ||
it("match:undefined", (t) => | ||
expect(match(undefined, undefined)).to.equal(true)); | ||
@@ -51,5 +52,7 @@ /** | ||
it("match:function_arrow", (t) => expect(match(18, (x) => x > 5)).to.equal(true)); | ||
it("match:function_arrow", (t) => | ||
expect(match(18, (x) => x > 5)).to.equal(true)); | ||
it("match:function_false", (t) => expect(match(18, (x) => x < 5)).to.equal(false)); | ||
it("match:function_false", (t) => | ||
expect(match(18, (x) => x < 5)).to.equal(false)); | ||
@@ -68,3 +71,5 @@ /** | ||
it("match:object_more_keys_value", (t) => | ||
expect(match({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal(false)); | ||
expect(match({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal( | ||
false | ||
)); | ||
@@ -89,2 +94,5 @@ it("match:object_more_keys_expected", (t) => | ||
it("match:object_same_lenght_different_keys", (t) => | ||
expect(match({ value: {} }, { league: {} })).to.equal(false)); | ||
/** | ||
@@ -95,3 +103,4 @@ * Arrays | ||
it("match:array", (t) => expect(match([1, 2, "hola"], [1, 2, "hola"])).to.equal(true)); | ||
it("match:array", (t) => | ||
expect(match([1, 2, "hola"], [1, 2, "hola"])).to.equal(true)); | ||
@@ -107,3 +116,6 @@ it("match:array_different", (t) => | ||
it("match:array_with_objects_missing", (t) => | ||
it("match:array_with_object_with_less_keys", (t) => | ||
expect(match([1, {}], [1, { test: "aaa" }])).to.equal(false)); | ||
it("match:array_with_object_with_more_keys", (t) => | ||
expect(match([1, { test: "aaa" }], [1, {}])).to.equal(false)); | ||
@@ -122,3 +134,4 @@ | ||
it("match:array_same", (t) => expect(match([333, 222], [333, 222])).to.equal(true)); | ||
it("match:array_same", (t) => | ||
expect(match([333, 222], [333, 222])).to.equal(true)); | ||
@@ -129,3 +142,3 @@ it("match:array_with_objects_different_key", (t) => | ||
it("match:array_with_objects_missing_string", (t) => | ||
expect(match([1, { test: "aaa", key2: 33 }], [1, { key2: 33 }])).to.equal( | ||
expect(match([1, { key2: 33 }], [1, { test: "aaa", key2: 33 }])).to.equal( | ||
false | ||
@@ -135,3 +148,3 @@ )); | ||
it("match:array_with_objects_missing_int", (t) => | ||
expect(match([1, { test: "aaa", key2: 33 }], [1, { test: "aaa" }])).to.equal( | ||
expect(match([1, { test: "aaa" }], [1, { test: "aaa", key2: 33 }])).to.equal( | ||
false | ||
@@ -146,9 +159,18 @@ )); | ||
it("match:map_equal", (t) => | ||
expect(match({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal(true)); | ||
expect(match({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal( | ||
true | ||
)); | ||
it("match:map_different", (t) => | ||
expect(match({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal(false)); | ||
expect(match({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal( | ||
false | ||
)); | ||
it("match:map_with_mote_keys", (t) => | ||
it("match:map_with_more_keys", (t) => | ||
expect( | ||
match({ name: "oscar", number: 18 }, new Map([["name", "oscar"]])) | ||
).to.equal(false)); | ||
it("match:map_with_less_keys", (t) => | ||
expect( | ||
match( | ||
@@ -163,7 +185,2 @@ { name: "oscar" }, | ||
it("match:map_with_less_keys", (t) => | ||
expect( | ||
match({ name: "", number: 18 }, new Map([["name", "oscar"]])) | ||
).to.equal(false)); | ||
it("match:map_with_regex_and_functions", (t) => | ||
@@ -207,6 +224,9 @@ expect( | ||
it("match:set", (t) => expect(match([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true)); | ||
it("match:set", (t) => | ||
expect(match([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true)); | ||
it("match:set_different", (t) => | ||
expect(match([1, true, "adios"], new Set([1, false, "hola"]))).to.equal(false)); | ||
expect(match([1, true, "adios"], new Set([1, false, "hola"]))).to.equal( | ||
false | ||
)); | ||
@@ -223,8 +243,16 @@ it("match:set_with_more_values", (t) => | ||
it("match:types_number", (t) => expect(match(3.1415, Number)).to.equal(true)); | ||
it("match:types_number_wrong", (t) => expect(match(3.1415, String)).to.equal(false)); | ||
it("match:types_string", (t) => expect(match("a boring string", String)).to.equal(true)); | ||
it("match:types_number_wrong", (t) => | ||
expect(match(3.1415, String)).to.equal(false)); | ||
it("match:types_string", (t) => | ||
expect(match("a boring string", String)).to.equal(true)); | ||
it("match:types_string_wrong", (t) => | ||
expect(match("a boring string", Boolean)).to.equal(false)); | ||
it("match:types_boolean", (t) => expect(match(true, Boolean)).to.equal(true)); | ||
it("match:types_boolean_wrong", (t) => expect(match(false, String)).to.equal(false)); | ||
it("match:types_boolean_wrong", (t) => | ||
expect(match(false, String)).to.equal(false)); | ||
it("match:types_object", (t) => expect(match({}, Object)).to.equal(true)); | ||
it("match:types_array", (t) => expect(match([], Array)).to.equal(true)); | ||
it("match:types_object_wrong", (t) => | ||
expect(match([], Object)).to.equal(false)); | ||
it("match:types_array_wrong", (t) => expect(match({}, Array)).to.equal(false)); | ||
@@ -231,0 +259,0 @@ /** |
@@ -6,3 +6,3 @@ "use strict"; | ||
const { expect } = require('@hapi/code'); | ||
const { expect } = require("@hapi/code"); | ||
const { it } = (exports.lab = Lab.script()); | ||
@@ -27,7 +27,9 @@ | ||
it("partial:boolean_false", (t) => expect(partial(false, false)).to.equal(true)); | ||
it("partial:boolean_false", (t) => | ||
expect(partial(false, false)).to.equal(true)); | ||
it("partial:boolean_true", (t) => expect(partial(false, false)).to.equal(true)); | ||
it("partial:boolean_true", (t) => expect(partial(true, true)).to.equal(true)); | ||
it("partial:undefined", (t) => expect(partial(undefined, undefined)).to.equal(true)); | ||
it("partial:undefined", (t) => | ||
expect(partial(undefined, undefined)).to.equal(true)); | ||
@@ -37,3 +39,4 @@ /** | ||
*/ | ||
it("partial:regexp", (t) => expect(partial("hola k ase?", /k ase/)).to.equal(true)); | ||
it("partial:regexp", (t) => | ||
expect(partial("hola k ase?", /k ase/)).to.equal(true)); | ||
@@ -47,9 +50,13 @@ it("partial:regexp_no_match", (t) => | ||
it("partial:function", (t) => | ||
expect(partial(18, function (x) { | ||
return x > 5; | ||
})).to.equal(true)); | ||
expect( | ||
partial(18, function (x) { | ||
return x > 5; | ||
}) | ||
).to.equal(true)); | ||
it("partial:function_arrow", (t) => expect(partial(18, (x) => x > 5)).to.equal(true)); | ||
it("partial:function_arrow", (t) => | ||
expect(partial(18, (x) => x > 5)).to.equal(true)); | ||
it("partial:function_false", (t) => expect(partial(18, (x) => x < 5)).to.equal(false)); | ||
it("partial:function_false", (t) => | ||
expect(partial(18, (x) => x < 5)).to.equal(false)); | ||
@@ -68,6 +75,10 @@ /** | ||
it("partial:object_more_keys_value", (t) => | ||
expect(partial({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal(true)); | ||
expect(partial({ name: "oscar", number: 18 }, { name: "oscar" })).to.equal( | ||
true | ||
)); | ||
it("partial:object_more_keys_value2", (t) => | ||
expect(partial({ name: "oscar", number: 18 }, { number: 18 })).to.equal(true)); | ||
expect(partial({ name: "oscar", number: 18 }, { number: 18 })).to.equal( | ||
true | ||
)); | ||
@@ -92,2 +103,5 @@ it("partial:object_more_keys_expected", (t) => | ||
it("match:object_same_lenght_different_keys", (t) => | ||
expect(partial({ value: {} }, { league: {} })).to.equal(false)); | ||
/** | ||
@@ -99,5 +113,3 @@ * Arrays | ||
it("partial:array", (t) => | ||
expect( | ||
partial([1, 2, "hola"], [1, 2, "hola"]) | ||
).to.equal(true)); | ||
expect(partial([1, 2, "hola"], [1, 2, "hola"])).to.equal(true)); | ||
@@ -108,40 +120,31 @@ it("partial:array_different", (t) => | ||
it("partial:array_left_more_values", (t) => | ||
expect( | ||
partial([1, 2, "hola"], [1, 2]) | ||
).to.equal(false)); | ||
expect(partial([1, 2, "hola"], [1, 2])).to.equal(false)); | ||
it("partial:array_right_more_values", (t) => | ||
expect( | ||
partial([1, 2], [1, 2, "hola"]) | ||
).to.equal(false)); | ||
expect(partial([1, 2], [1, 2, "hola"])).to.equal(false)); | ||
it("partial:array_with_objects", (t) => | ||
expect( | ||
partial([1, {"test": "aaa"}], [1, {"test": "aaa"}]) | ||
).to.equal(true)); | ||
expect(partial([1, { test: "aaa" }], [1, { test: "aaa" }])).to.equal(true)); | ||
it("partial:array_with_objects_missing", (t) => | ||
expect( | ||
partial([1, {"test": "aaa"}], [1, {}]) | ||
).to.equal(true)); | ||
it("partial:array_with_object_with_less_keys", (t) => | ||
expect(partial([1, {}], [1, { test: "aaa" }])).to.equal(false)); | ||
it("partial:array_with_object_with_more_keys", (t) => | ||
expect(partial([1, { test: "aaa" }], [1, {}])).to.equal(true)); | ||
it("partial:array_with_objects_different_value", (t) => | ||
expect( | ||
partial([1, {"test": "aaa"}], [1, {"test": "b"}]) | ||
).to.equal(false)); | ||
expect(partial([1, { test: "aaa" }], [1, { test: "b" }])).to.equal(false)); | ||
it("partial:array_with_objects_different_key", (t) => | ||
expect( | ||
partial([1, {"test": "aaa"}], [1, {"test2": "aaa"}]) | ||
).to.equal(false)); | ||
expect(partial([1, { test: "aaa" }], [1, { test2: "aaa" }])).to.equal(false)); | ||
it("partial:array_with_objects_missing_string", (t) => | ||
expect( | ||
partial([1, {"test": "aaa", "key2": 33}], [1, {"key2": 33}]) | ||
).to.equal(true)); | ||
expect(partial([1, { key2: 33 }], [1, { test: "aaa", key2: 33 }])).to.equal( | ||
false | ||
)); | ||
it("partial:array_with_objects_missing_int", (t) => | ||
expect( | ||
partial([1, {"test": "aaa", "key2": 33}], [1, {"test": "aaa"}]) | ||
).to.equal(true)); | ||
partial([1, { test: "aaa" }], [1, { test: "aaa", key2: 33 }]) | ||
).to.equal(false)); | ||
@@ -154,17 +157,12 @@ /** | ||
it("partial:map_equal", (t) => | ||
expect(partial({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal(true)); | ||
expect(partial({ name: "oscar" }, new Map([["name", "oscar"]]))).to.equal( | ||
true | ||
)); | ||
it("partial:map_different", (t) => | ||
expect(partial({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal(false)); | ||
expect(partial({ name: "oscar" }, new Map([["name", "pedro"]]))).to.equal( | ||
false | ||
)); | ||
it("partial:map_with_mote_keys", (t) => | ||
expect(partial( | ||
{ name: "oscar" }, | ||
new Map([ | ||
["name", "oscar"], | ||
["number", 18], | ||
]) | ||
)).to.equal(false)); | ||
it("partial:map_with_less_keys", (t) => | ||
it("partial:map_with_more_keys", (t) => | ||
expect( | ||
@@ -174,28 +172,45 @@ partial({ name: "oscar", number: 18 }, new Map([["name", "oscar"]])) | ||
it("partial:map_with_less_keys", (t) => | ||
expect( | ||
partial( | ||
{ name: "oscar" }, | ||
new Map([ | ||
["name", "oscar"], | ||
["number", 18], | ||
]) | ||
) | ||
).to.equal(false)); | ||
it("partial:map_with_regex_and_functions", (t) => | ||
expect(partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /os/], | ||
["age", (x) => x > 18], | ||
]) | ||
)).to.equal(true)); | ||
expect( | ||
partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /os/], | ||
["age", (x) => x > 18], | ||
]) | ||
) | ||
).to.equal(true)); | ||
it("partial:map_with_regex_and_functions_fails", (t) => | ||
expect(partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /ped/], | ||
["age", (x) => x > 18], | ||
]) | ||
)).to.equal(false)); | ||
expect( | ||
partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /ped/], | ||
["age", (x) => x > 18], | ||
]) | ||
) | ||
).to.equal(false)); | ||
it("partial:map_with_regex_and_functions_fails_all", (t) => | ||
expect(partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /ped/], | ||
["age", (x) => x < 18], | ||
]) | ||
)).to.equal(false)); | ||
expect( | ||
partial( | ||
{ name: "oscar", age: 23 }, | ||
new Map([ | ||
["name", /ped/], | ||
["age", (x) => x < 18], | ||
]) | ||
) | ||
).to.equal(false)); | ||
@@ -207,6 +222,9 @@ /** | ||
it("partial:set", (t) => expect(partial([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true)); | ||
it("partial:set", (t) => | ||
expect(partial([1, 2, "hola"], new Set([1, 2, "hola"]))).to.equal(true)); | ||
it("partial:set_different", (t) => | ||
expect(partial([1, true, "adios"], new Set([1, false, "hola"]))).to.equal(false)); | ||
expect(partial([1, true, "adios"], new Set([1, false, "hola"]))).to.equal( | ||
false | ||
)); | ||
@@ -222,8 +240,20 @@ it("partial:set_with_more_values", (t) => | ||
*/ | ||
it("partial:types_number", (t) => expect(partial(3.1415, Number)).to.equal(true)); | ||
it("partial:types_number_wrong", (t) => expect(partial(3.1415, String)).to.equal(false)); | ||
it("partial:types_string", (t) => expect(partial("a boring string", String)).to.equal(true)); | ||
it("partial:types_string_wrong", (t) => expect(partial("a boring string", Boolean)).to.equal(false)); | ||
it("partial:types_boolean", (t) => expect(partial(true, Boolean)).to.equal(true)); | ||
it("partial:types_boolean_wrong", (t) => expect(partial(false, String)).to.equal(false)); | ||
it("partial:types_number", (t) => | ||
expect(partial(3.1415, Number)).to.equal(true)); | ||
it("partial:types_number_wrong", (t) => | ||
expect(partial(3.1415, String)).to.equal(false)); | ||
it("partial:types_string", (t) => | ||
expect(partial("a boring string", String)).to.equal(true)); | ||
it("partial:types_string_wrong", (t) => | ||
expect(partial("a boring string", Boolean)).to.equal(false)); | ||
it("partial:types_boolean", (t) => | ||
expect(partial(true, Boolean)).to.equal(true)); | ||
it("partial:types_boolean_wrong", (t) => | ||
expect(partial(false, String)).to.equal(false)); | ||
it("partial:types_object", (t) => expect(partial({}, Object)).to.equal(true)); | ||
it("partial:types_array", (t) => expect(partial([], Array)).to.equal(true)); | ||
it("partial:types_object_wrong", (t) => | ||
expect(partial([], Object)).to.equal(false)); | ||
it("partial:types_array_wrong", (t) => | ||
expect(partial({}, Array)).to.equal(false)); | ||
@@ -236,14 +266,14 @@ /** | ||
partial( | ||
{ | ||
name: { first: "Walter", last: "White" }, | ||
age: 51, | ||
breakingBad: true, | ||
}, | ||
{ | ||
name: { first: /[\w]*/, last: "White" }, | ||
age: (age) => age > 18, | ||
breakingBad: Boolean, | ||
} | ||
) | ||
).to.equal(true)); | ||
{ | ||
name: { first: "Walter", last: "White" }, | ||
age: 51, | ||
breakingBad: true, | ||
}, | ||
{ | ||
name: { first: /[\w]*/, last: "White" }, | ||
age: (age) => age > 18, | ||
breakingBad: Boolean, | ||
} | ||
) | ||
).to.equal(true)); | ||
@@ -250,0 +280,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27357
12
644