How to use match.isMatcher method in sinon

Best JavaScript code snippet using sinon

match-test.js

Source:match-test.js Github

copy

Full Screen

...6 function propertyMatcherTests(matcher) {7 return {8 "returns matcher": function () {9 var has = matcher("foo");10 assert(sinon.match.isMatcher(has));11 },12 "throws if first argument is not string": function () {13 assert.exception(function () {14 matcher();15 }, "TypeError");16 assert.exception(function () {17 matcher(123);18 }, "TypeError");19 },20 "returns false if value is undefined or null": function () {21 var has = matcher("foo");22 assert.isFalse(has.test(undefined));23 assert.isFalse(has.test(null));24 },25 "returns true if object has property": function () {26 var has = matcher("foo");27 assert(has.test({ foo: null }));28 },29 "returns false if object value is not equal to given value": function () {30 var has = matcher("foo", 1);31 assert.isFalse(has.test({ foo: null }));32 },33 "returns true if object value is equal to given value": function () {34 var has = matcher("message", "sinon rocks");35 assert(has.test({ message: "sinon rocks" }));36 assert(has.test(new Error("sinon rocks")));37 },38 "returns true if string property matches": function () {39 var has = matcher("length", 5);40 assert(has.test("sinon"));41 },42 "allows to expect undefined": function () {43 var has = matcher("foo", undefined);44 assert.isFalse(has.test({ foo: 1 }));45 },46 "compares value deeply": function () {47 var has = matcher("foo", { bar: "doo", test: 42 });48 assert(has.test({ foo: { bar: "doo", test: 42 } }));49 },50 "compares with matcher": function () {51 var has = matcher("callback", sinon.match.typeOf("function"));52 assert(has.test({ callback: function () {} }));53 }54 };55 }56 buster.testCase("sinon.match", {57 "returns matcher": function () {58 var match = sinon.match(function () {});59 assert(sinon.match.isMatcher(match));60 },61 "exposes test function": function () {62 var test = function () {};63 var match = sinon.match(test);64 assert.same(match.test, test);65 },66 "returns true if properties are equal": function () {67 var match = sinon.match({ str: "sinon", nr: 1 });68 assert(match.test({ str: "sinon", nr: 1, other: "ignored" }));69 },70 "returns true if properties are deep equal": function () {71 var match = sinon.match({ deep: { str: "sinon" } });72 assert(match.test({ deep: { str: "sinon", ignored: "value" } }));73 },74 "returns false if a property is not equal": function () {75 var match = sinon.match({ str: "sinon", nr: 1 });76 assert.isFalse(match.test({ str: "sinon", nr: 2 }));77 },78 "returns false if a property is missing": function () {79 var match = sinon.match({ str: "sinon", nr: 1 });80 assert.isFalse(match.test({ nr: 1 }));81 },82 "returns true if array is equal": function () {83 var match = sinon.match({ arr: ["a", "b"] });84 assert(match.test({ arr: ["a", "b"] }));85 },86 "returns false if array is not equal": function () {87 var match = sinon.match({ arr: ["b", "a"] });88 assert.isFalse(match.test({ arr: ["a", "b"] }));89 },90 "returns true if number objects are equal": function () {91 /*eslint-disable no-new-wrappers*/92 var match = sinon.match({ one: new Number(1) });93 assert(match.test({ one: new Number(1) }));94 /*eslint-enable no-new-wrappers*/95 },96 "returns true if test matches": function () {97 var match = sinon.match({ prop: sinon.match.typeOf("boolean") });98 assert(match.test({ prop: true }));99 },100 "returns false if test does not match": function () {101 var match = sinon.match({ prop: sinon.match.typeOf("boolean") });102 assert.isFalse(match.test({ prop: "no" }));103 },104 "returns true if deep test matches": function () {105 var match = sinon.match({ deep: { prop: sinon.match.typeOf("boolean") } });106 assert(match.test({ deep: { prop: true } }));107 },108 "returns false if deep test does not match": function () {109 var match = sinon.match({ deep: { prop: sinon.match.typeOf("boolean") } });110 assert.isFalse(match.test({ deep: { prop: "no" } }));111 },112 "returns false if tested value is null or undefined": function () {113 var match = sinon.match({});114 assert.isFalse(match.test(null));115 assert.isFalse(match.test(undefined));116 },117 "returns true if error message matches": function () {118 var match = sinon.match({ message: "evil error" });119 assert(match.test(new Error("evil error")));120 },121 "returns true if string property matches": function () {122 var match = sinon.match({ length: 5 });123 assert(match.test("sinon"));124 },125 "returns true if number property matches": function () {126 var match = sinon.match({ toFixed: sinon.match.func });127 assert(match.test(0));128 },129 "returns true for string match": function () {130 var match = sinon.match("sinon");131 assert(match.test("sinon"));132 },133 "returns true for substring match": function () {134 var match = sinon.match("no");135 assert(match.test("sinon"));136 },137 "returns false for string mismatch": function () {138 var match = sinon.match("Sinon.JS");139 assert.isFalse(match.test(null));140 assert.isFalse(match.test({}));141 assert.isFalse(match.test("sinon"));142 assert.isFalse(match.test("sinon.js"));143 },144 "returns true for regexp match": function () {145 var match = sinon.match(/^[sino]+$/);146 assert(match.test("sinon"));147 },148 "returns false for regexp string mismatch": function () {149 var match = sinon.match(/^[sin]+$/);150 assert.isFalse(match.test("sinon"));151 },152 "returns false for regexp type mismatch": function () {153 var match = sinon.match(/.*/);154 assert.isFalse(match.test());155 assert.isFalse(match.test(null));156 assert.isFalse(match.test(123));157 assert.isFalse(match.test({}));158 },159 "returns true for number match": function () {160 var match = sinon.match(1);161 assert(match.test(1));162 assert(match.test("1"));163 assert(match.test(true));164 },165 "returns false for number mismatch": function () {166 var match = sinon.match(1);167 assert.isFalse(match.test());168 assert.isFalse(match.test(null));169 assert.isFalse(match.test(2));170 assert.isFalse(match.test(false));171 assert.isFalse(match.test({}));172 },173 "returns true if test function in object returns true": function () {174 var match = sinon.match({ test: function () {175 return true;176 }});177 assert(match.test());178 },179 "returns false if test function in object returns false": function () {180 var match = sinon.match({ test: function () {181 return false;182 }});183 assert.isFalse(match.test());184 },185 "returns false if test function in object returns nothing": function () {186 var match = sinon.match({ test: function () {}});187 assert.isFalse(match.test());188 },189 "passes actual value to test function in object": function () {190 var match = sinon.match({ test: function (arg) {191 return arg;192 }});193 assert(match.test(true));194 },195 "uses matcher": function () {196 var match = sinon.match(sinon.match("test"));197 assert(match.test("testing"));198 },199 ".toString": {200 "returns message": function () {201 var message = "hello sinon.match";202 var match = sinon.match(function () {}, message);203 assert.same(match.toString(), message);204 },205 "defaults to match(functionName)": function () {206 var match = sinon.match(function custom() {});207 assert.same(match.toString(), "match(custom)");208 }209 },210 ".any": {211 "is matcher": function () {212 assert(sinon.match.isMatcher(sinon.match.any));213 },214 "returns true when tested": function () {215 assert(sinon.match.any.test());216 }217 },218 ".defined": {219 "is matcher": function () {220 assert(sinon.match.isMatcher(sinon.match.defined));221 },222 "returns false if test is called with null": function () {223 assert.isFalse(sinon.match.defined.test(null));224 },225 "returns false if test is called with undefined": function () {226 assert.isFalse(sinon.match.defined.test(undefined));227 },228 "returns true if test is called with any value": function () {229 assert(sinon.match.defined.test(false));230 assert(sinon.match.defined.test(true));231 assert(sinon.match.defined.test(0));232 assert(sinon.match.defined.test(1));233 assert(sinon.match.defined.test(""));234 },235 "returns true if test is called with any object": function () {236 assert(sinon.match.defined.test({}));237 assert(sinon.match.defined.test(function () {}));238 }239 },240 ".truthy": {241 "is matcher": function () {242 assert(sinon.match.isMatcher(sinon.match.truthy));243 },244 "returns true if test is called with trueish value": function () {245 assert(sinon.match.truthy.test(true));246 assert(sinon.match.truthy.test(1));247 assert(sinon.match.truthy.test("yes"));248 },249 "returns false if test is called falsy value": function () {250 assert.isFalse(sinon.match.truthy.test(false));251 assert.isFalse(sinon.match.truthy.test(null));252 assert.isFalse(sinon.match.truthy.test(undefined));253 assert.isFalse(sinon.match.truthy.test(""));254 }255 },256 ".falsy": {257 "is matcher": function () {258 assert(sinon.match.isMatcher(sinon.match.falsy));259 },260 "returns true if test is called falsy value": function () {261 assert(sinon.match.falsy.test(false));262 assert(sinon.match.falsy.test(null));263 assert(sinon.match.falsy.test(undefined));264 assert(sinon.match.falsy.test(""));265 },266 "returns false if test is called with trueish value": function () {267 assert.isFalse(sinon.match.falsy.test(true));268 assert.isFalse(sinon.match.falsy.test(1));269 assert.isFalse(sinon.match.falsy.test("yes"));270 }271 },272 ".same": {273 "returns matcher": function () {274 var same = sinon.match.same();275 assert(sinon.match.isMatcher(same));276 },277 "returns true if test is called with same argument": function () {278 var object = {};279 var same = sinon.match.same(object);280 assert(same.test(object));281 },282 "returns false if test is not called with same argument": function () {283 var same = sinon.match.same({});284 assert.isFalse(same.test({}));285 }286 },287 ".typeOf": {288 "throws if given argument is not a string": function () {289 assert.exception(function () {290 sinon.match.typeOf();291 }, "TypeError");292 assert.exception(function () {293 sinon.match.typeOf(123);294 }, "TypeError");295 },296 "returns matcher": function () {297 var typeOf = sinon.match.typeOf("string");298 assert(sinon.match.isMatcher(typeOf));299 },300 "returns true if test is called with string": function () {301 var typeOf = sinon.match.typeOf("string");302 assert(typeOf.test("Sinon.JS"));303 },304 "returns false if test is not called with string": function () {305 var typeOf = sinon.match.typeOf("string");306 assert.isFalse(typeOf.test(123));307 },308 "returns true if test is called with regexp": function () {309 var typeOf = sinon.match.typeOf("regexp");310 assert(typeOf.test(/.+/));311 },312 "returns false if test is not called with regexp": function () {313 var typeOf = sinon.match.typeOf("regexp");314 assert.isFalse(typeOf.test(true));315 }316 },317 ".instanceOf": {318 "throws if given argument is not a function": function () {319 assert.exception(function () {320 sinon.match.instanceOf();321 }, "TypeError");322 assert.exception(function () {323 sinon.match.instanceOf("foo");324 }, "TypeError");325 },326 "returns matcher": function () {327 var instanceOf = sinon.match.instanceOf(function () {});328 assert(sinon.match.isMatcher(instanceOf));329 },330 "returns true if test is called with instance of argument": function () {331 var instanceOf = sinon.match.instanceOf(Array);332 assert(instanceOf.test([]));333 },334 "returns false if test is not called with instance of argument": function () {335 var instanceOf = sinon.match.instanceOf(Array);336 assert.isFalse(instanceOf.test({}));337 }338 },339 ".has": propertyMatcherTests(sinon.match.has),340 ".hasOwn": propertyMatcherTests(sinon.match.hasOwn),341 ".hasSpecial": {342 "returns true if object has inherited property": function () {343 var has = sinon.match.has("toString");344 assert(has.test({}));345 },346 "only includes property in message": function () {347 var has = sinon.match.has("test");348 assert.equals(has.toString(), "has(\"test\")");349 },350 "includes property and value in message": function () {351 var has = sinon.match.has("test", undefined);352 assert.equals(has.toString(), "has(\"test\", undefined)");353 },354 "returns true if string function matches": function () {355 var has = sinon.match.has("toUpperCase", sinon.match.func);356 assert(has.test("sinon"));357 },358 "returns true if number function matches": function () {359 var has = sinon.match.has("toFixed", sinon.match.func);360 assert(has.test(0));361 }362 },363 ".hasOwnSpecial": {364 "returns false if object has inherited property": function () {365 var hasOwn = sinon.match.hasOwn("toString");366 assert.isFalse(hasOwn.test({}));367 },368 "only includes property in message": function () {369 var hasOwn = sinon.match.hasOwn("test");370 assert.equals(hasOwn.toString(), "hasOwn(\"test\")");371 },372 "includes property and value in message": function () {373 var hasOwn = sinon.match.hasOwn("test", undefined);374 assert.equals(hasOwn.toString(), "hasOwn(\"test\", undefined)");375 }376 },377 ".bool": {378 "is typeOf boolean matcher": function () {379 var bool = sinon.match.bool;380 assert(sinon.match.isMatcher(bool));381 assert.equals(bool.toString(), "typeOf(\"boolean\")");382 }383 },384 ".number": {385 "is typeOf number matcher": function () {386 var number = sinon.match.number;387 assert(sinon.match.isMatcher(number));388 assert.equals(number.toString(), "typeOf(\"number\")");389 }390 },391 ".string": {392 "is typeOf string matcher": function () {393 var string = sinon.match.string;394 assert(sinon.match.isMatcher(string));395 assert.equals(string.toString(), "typeOf(\"string\")");396 }397 },398 ".object": {399 "is typeOf object matcher": function () {400 var object = sinon.match.object;401 assert(sinon.match.isMatcher(object));402 assert.equals(object.toString(), "typeOf(\"object\")");403 }404 },405 ".func": {406 "is typeOf function matcher": function () {407 var func = sinon.match.func;408 assert(sinon.match.isMatcher(func));409 assert.equals(func.toString(), "typeOf(\"function\")");410 }411 },412 ".array": {413 "is typeOf array matcher": function () {414 var array = sinon.match.array;415 assert(sinon.match.isMatcher(array));416 assert.equals(array.toString(), "typeOf(\"array\")");417 }418 },419 ".regexp": {420 "is typeOf regexp matcher": function () {421 var regexp = sinon.match.regexp;422 assert(sinon.match.isMatcher(regexp));423 assert.equals(regexp.toString(), "typeOf(\"regexp\")");424 }425 },426 ".date": {427 "is typeOf regexp matcher": function () {428 var date = sinon.match.date;429 assert(sinon.match.isMatcher(date));430 assert.equals(date.toString(), "typeOf(\"date\")");431 }432 },433 ".or": {434 "is matcher": function () {435 var numberOrString = sinon.match.number.or(sinon.match.string);436 assert(sinon.match.isMatcher(numberOrString));437 assert.equals(numberOrString.toString(),438 "typeOf(\"number\").or(typeOf(\"string\"))");439 },440 "requires matcher argument": function () {441 assert.exception(function () {442 sinon.match.instanceOf(Error).or();443 }, "TypeError");444 },445 "will coerce argument to matcher": function () {446 var abcOrDef = sinon.match("abc").or("def");447 assert(sinon.match.isMatcher(abcOrDef));448 assert.equals(abcOrDef.toString(),449 "match(\"abc\").or(match(\"def\"))");450 },451 "returns true if either matcher matches": function () {452 var numberOrString = sinon.match.number.or(sinon.match.string);453 assert(numberOrString.test(123));454 assert(numberOrString.test("abc"));455 },456 "returns false if neither matcher matches": function () {457 var numberOrAbc = sinon.match.number.or("abc");458 assert.isFalse(numberOrAbc.test(/.+/));459 assert.isFalse(numberOrAbc.test(new Date()));460 assert.isFalse(numberOrAbc.test({}));461 },462 "can be used with undefined": function () {463 var numberOrUndef = sinon.match.number.or(undefined);464 assert(numberOrUndef.test(123));465 assert(numberOrUndef.test(undefined));466 }467 },468 ".and": {469 "is matcher": function () {470 var fooAndBar = sinon.match.has("foo").and(sinon.match.has("bar"));471 assert(sinon.match.isMatcher(fooAndBar));472 assert.equals(fooAndBar.toString(), "has(\"foo\").and(has(\"bar\"))");473 },474 "requires matcher argument": function () {475 assert.exception(function () {476 sinon.match.instanceOf(Error).and();477 }, "TypeError");478 },479 "will coerce to matcher": function () {480 var abcOrObj = sinon.match("abc").or({a: 1});481 assert(sinon.match.isMatcher(abcOrObj));482 assert.equals(abcOrObj.toString(),483 "match(\"abc\").or(match(a: 1))");484 },485 "returns true if both matchers match": function () {486 var fooAndBar = sinon.match.has("foo").and({ bar: "bar" });487 assert(fooAndBar.test({ foo: "foo", bar: "bar" }));488 },489 "returns false if either matcher does not match": function () {490 var fooAndBar = sinon.match.has("foo").and(sinon.match.has("bar"));491 assert.isFalse(fooAndBar.test({ foo: "foo" }));492 assert.isFalse(fooAndBar.test({ bar: "bar" }));493 },494 "can be used with undefined": function () {495 var falsyAndUndefined = sinon.match.falsy.and(undefined);...

Full Screen

Full Screen

match_test.js

Source:match_test.js Github

copy

Full Screen

...13function propertyMatcherTests(matcher) {14 return {15 "returns matcher": function () {16 var has = matcher("foo");17 assert(sinon.match.isMatcher(has));18 },19 "throws if first argument is not string": function () {20 assert.exception(function () {21 matcher();22 }, "TypeError");23 assert.exception(function () {24 matcher(123);25 }, "TypeError");26 },27 "returns false if value is undefined or null": function () {28 var has = matcher("foo");29 assert.isFalse(has.test(undefined));30 assert.isFalse(has.test(null));31 },32 "returns true if object has property": function () {33 var has = matcher("foo");34 assert(has.test({ foo: null }));35 },36 "returns false if object value is not equal to given value": function () {37 var has = matcher("foo", 1);38 assert.isFalse(has.test({ foo: null }));39 },40 "returns true if object value is equal to given value": function () {41 var has = matcher("message", "sinon rocks");42 assert(has.test({ message: "sinon rocks" }));43 assert(has.test(new Error("sinon rocks")));44 },45 "returns true if string property matches": function () {46 var has = matcher("length", 5);47 assert(has.test("sinon"));48 },49 "allows to expect undefined": function () {50 var has = matcher("foo", undefined);51 assert.isFalse(has.test({ foo: 1 }));52 },53 "compares value deeply": function () {54 var has = matcher("foo", { bar: "doo", test: 42 });55 assert(has.test({ foo: { bar: "doo", test: 42 } }));56 },57 "compares with matcher": function () {58 var has = matcher("callback", sinon.match.typeOf("function"));59 assert(has.test({ callback: function () {} }));60 }61 };62}63buster.testCase("sinon.match", {64 "returns matcher": function () {65 var match = sinon.match(function () {});66 assert(sinon.match.isMatcher(match));67 },68 "exposes test function": function () {69 var test = function () {};70 var match = sinon.match(test);71 assert.same(match.test, test);72 },73 "returns true if properties are equal": function () {74 var match = sinon.match({ str: "sinon", nr: 1 });75 assert(match.test({ str: "sinon", nr: 1, other: "ignored" }));76 },77 "returns true if properties are deep equal": function () {78 var match = sinon.match({ deep: { str: "sinon" } });79 assert(match.test({ deep: { str: "sinon", ignored: "value" } }));80 },81 "returns false if a property is not equal": function () {82 var match = sinon.match({ str: "sinon", nr: 1 });83 assert.isFalse(match.test({ str: "sinon", nr: 2 }));84 },85 "returns false if a property is missing": function () {86 var match = sinon.match({ str: "sinon", nr: 1 });87 assert.isFalse(match.test({ nr: 1 }));88 },89 "returns true if array is equal": function () {90 var match = sinon.match({ arr: ["a", "b"] });91 assert(match.test({ arr: ["a", "b"] }));92 },93 "returns false if array is not equal": function () {94 var match = sinon.match({ arr: ["b", "a"] });95 assert.isFalse(match.test({ arr: ["a", "b"] }));96 },97 "returns true if number objects are equal": function () {98 var match = sinon.match({ one: new Number(1) });99 assert(match.test({ one: new Number(1) }));100 },101 "returns true if test matches": function () {102 var match = sinon.match({ prop: sinon.match.typeOf("boolean") });103 assert(match.test({ prop: true }));104 },105 "returns false if test does not match": function () {106 var match = sinon.match({ prop: sinon.match.typeOf("boolean") });107 assert.isFalse(match.test({ prop: "no" }));108 },109 "returns true if deep test matches": function () {110 var match = sinon.match({ deep: { prop: sinon.match.typeOf("boolean") } });111 assert(match.test({ deep: { prop: true } }));112 },113 "returns false if deep test does not match": function () {114 var match = sinon.match({ deep: { prop: sinon.match.typeOf("boolean") } });115 assert.isFalse(match.test({ deep: { prop: "no" } }));116 },117 "returns false if tested value is null or undefined": function () {118 var match = sinon.match({});119 assert.isFalse(match.test(null));120 assert.isFalse(match.test(undefined));121 },122 "returns true if error message matches": function () {123 var match = sinon.match({ message: "evil error" });124 assert(match.test(new Error("evil error")));125 },126 "returns true if string property matches": function () {127 var match = sinon.match({ length: 5 });128 assert(match.test("sinon"));129 },130 "returns true if number property matches": function () {131 var match = sinon.match({ toFixed: sinon.match.func });132 assert(match.test(0));133 },134 "returns true for string match": function () {135 var match = sinon.match("sinon");136 assert(match.test("sinon"));137 },138 "returns true for substring match": function () {139 var match = sinon.match("no");140 assert(match.test("sinon"));141 },142 "returns false for string mismatch": function () {143 var match = sinon.match("Sinon.JS");144 assert.isFalse(match.test(null));145 assert.isFalse(match.test({}));146 assert.isFalse(match.test("sinon"));147 assert.isFalse(match.test("sinon.js"));148 },149 "returns true for regexp match": function () {150 var match = sinon.match(/^[sino]+$/);151 assert(match.test("sinon"));152 },153 "returns false for regexp string mismatch": function () {154 var match = sinon.match(/^[sin]+$/);155 assert.isFalse(match.test("sinon"));156 },157 "returns false for regexp type mismatch": function () {158 var match = sinon.match(/.*/);159 assert.isFalse(match.test());160 assert.isFalse(match.test(null));161 assert.isFalse(match.test(123));162 assert.isFalse(match.test({}));163 },164 "returns true for number match": function () {165 var match = sinon.match(1);166 assert(match.test(1));167 assert(match.test("1"));168 assert(match.test(true));169 },170 "returns false for number mismatch": function () {171 var match = sinon.match(1);172 assert.isFalse(match.test());173 assert.isFalse(match.test(null));174 assert.isFalse(match.test(2));175 assert.isFalse(match.test(false));176 assert.isFalse(match.test({}));177 },178 "returns true if test function in object returns true": function () {179 var match = sinon.match({ test: function () { return true; }});180 assert(match.test());181 },182 "returns false if test function in object returns false": function () {183 var match = sinon.match({ test: function () { return false; }});184 assert.isFalse(match.test());185 },186 "returns false if test function in object returns nothing": function () {187 var match = sinon.match({ test: function () {}});188 assert.isFalse(match.test());189 },190 "passes actual value to test function in object": function () {191 var match = sinon.match({ test: function (arg) { return arg; }});192 assert(match.test(true));193 },194 "uses matcher": function () {195 var match = sinon.match(sinon.match("test"));196 assert(match.test("testing"));197 },198 ".toString": {199 "returns message": function () {200 var message = "hello sinon.match";201 var match = sinon.match(function () {}, message);202 assert.same(match.toString(), message);203 },204 "defaults to match(functionName)": function () {205 var match = sinon.match(function custom() {});206 assert.same(match.toString(), "match(custom)");207 }208 },209 ".any": {210 "is matcher": function () {211 assert(sinon.match.isMatcher(sinon.match.any));212 },213 "returns true when tested": function () {214 assert(sinon.match.any.test());215 }216 },217 ".defined": {218 "is matcher": function () {219 assert(sinon.match.isMatcher(sinon.match.defined));220 },221 "returns false if test is called with null": function () {222 assert.isFalse(sinon.match.defined.test(null));223 },224 "returns false if test is called with undefined": function () {225 assert.isFalse(sinon.match.defined.test(undefined));226 },227 "returns true if test is called with any value": function () {228 assert(sinon.match.defined.test(false));229 assert(sinon.match.defined.test(true));230 assert(sinon.match.defined.test(0));231 assert(sinon.match.defined.test(1));232 assert(sinon.match.defined.test(""));233 },234 "returns true if test is called with any object": function () {235 assert(sinon.match.defined.test({}));236 assert(sinon.match.defined.test(function () {}));237 }238 },239 ".truthy": {240 "is matcher": function () {241 assert(sinon.match.isMatcher(sinon.match.truthy));242 },243 "returns true if test is called with trueish value": function () {244 assert(sinon.match.truthy.test(true));245 assert(sinon.match.truthy.test(1));246 assert(sinon.match.truthy.test("yes"));247 },248 "returns false if test is called falsy value": function () {249 assert.isFalse(sinon.match.truthy.test(false));250 assert.isFalse(sinon.match.truthy.test(null));251 assert.isFalse(sinon.match.truthy.test(undefined));252 assert.isFalse(sinon.match.truthy.test(""));253 }254 },255 ".falsy": {256 "is matcher": function () {257 assert(sinon.match.isMatcher(sinon.match.falsy));258 },259 "returns true if test is called falsy value": function () {260 assert(sinon.match.falsy.test(false));261 assert(sinon.match.falsy.test(null));262 assert(sinon.match.falsy.test(undefined));263 assert(sinon.match.falsy.test(""));264 },265 "returns false if test is called with trueish value": function () {266 assert.isFalse(sinon.match.falsy.test(true));267 assert.isFalse(sinon.match.falsy.test(1));268 assert.isFalse(sinon.match.falsy.test("yes"));269 }270 },271 ".same": {272 "returns matcher": function () {273 var same = sinon.match.same();274 assert(sinon.match.isMatcher(same));275 },276 "returns true if test is called with same argument": function () {277 var object = {};278 var same = sinon.match.same(object);279 assert(same.test(object));280 },281 "returns false if test is not called with same argument": function () {282 var same = sinon.match.same({});283 assert.isFalse(same.test({}));284 }285 },286 ".typeOf": {287 "throws if given argument is not a string": function () {288 assert.exception(function () {289 sinon.match.typeOf();290 }, "TypeError");291 assert.exception(function () {292 sinon.match.typeOf(123);293 }, "TypeError");294 },295 "returns matcher": function () {296 var typeOf = sinon.match.typeOf("string");297 assert(sinon.match.isMatcher(typeOf));298 },299 "returns true if test is called with string": function () {300 var typeOf = sinon.match.typeOf("string");301 assert(typeOf.test("Sinon.JS"));302 },303 "returns false if test is not called with string": function () {304 var typeOf = sinon.match.typeOf("string");305 assert.isFalse(typeOf.test(123));306 },307 "returns true if test is called with regexp": function () {308 var typeOf = sinon.match.typeOf("regexp");309 assert(typeOf.test(/.+/));310 },311 "returns false if test is not called with regexp": function () {312 var typeOf = sinon.match.typeOf("regexp");313 assert.isFalse(typeOf.test(true));314 }315 },316 ".instanceOf": {317 "throws if given argument is not a function": function () {318 assert.exception(function () {319 sinon.match.instanceOf();320 }, "TypeError");321 assert.exception(function () {322 sinon.match.instanceOf("foo");323 }, "TypeError");324 },325 "returns matcher": function () {326 var instanceOf = sinon.match.instanceOf(function () {});327 assert(sinon.match.isMatcher(instanceOf));328 },329 "returns true if test is called with instance of argument": function () {330 var instanceOf = sinon.match.instanceOf(Array);331 assert(instanceOf.test([]));332 },333 "returns false if test is not called with instance of argument": function () {334 var instanceOf = sinon.match.instanceOf(Array);335 assert.isFalse(instanceOf.test({}));336 }337 },338 ".has": propertyMatcherTests(sinon.match.has),339 ".hasOwn": propertyMatcherTests(sinon.match.hasOwn),340 ".hasSpecial": {341 "returns true if object has inherited property": function () {342 var has = sinon.match.has("toString");343 assert(has.test({}));344 },345 "only includes property in message": function () {346 var has = sinon.match.has("test");347 assert.equals(has.toString(), "has(\"test\")");348 },349 "includes property and value in message": function () {350 var has = sinon.match.has("test", undefined);351 assert.equals(has.toString(), "has(\"test\", undefined)");352 },353 "returns true if string function matches": function () {354 var has = sinon.match.has("toUpperCase", sinon.match.func);355 assert(has.test("sinon"));356 },357 "returns true if number function matches": function () {358 var has = sinon.match.has("toFixed", sinon.match.func);359 assert(has.test(0));360 }361 },362 ".hasOwnSpecial": {363 "returns false if object has inherited property": function () {364 var hasOwn = sinon.match.hasOwn("toString");365 assert.isFalse(hasOwn.test({}));366 },367 "only includes property in message": function () {368 var hasOwn = sinon.match.hasOwn("test");369 assert.equals(hasOwn.toString(), "hasOwn(\"test\")");370 },371 "includes property and value in message": function () {372 var hasOwn = sinon.match.hasOwn("test", undefined);373 assert.equals(hasOwn.toString(), "hasOwn(\"test\", undefined)");374 }375 },376 ".bool": {377 "is typeOf boolean matcher": function () {378 var bool = sinon.match.bool;379 assert(sinon.match.isMatcher(bool));380 assert.equals(bool.toString(), "typeOf(\"boolean\")");381 }382 },383 ".number": {384 "is typeOf number matcher": function () {385 var number = sinon.match.number;386 assert(sinon.match.isMatcher(number));387 assert.equals(number.toString(), "typeOf(\"number\")");388 }389 },390 ".string": {391 "is typeOf string matcher": function () {392 var string = sinon.match.string;393 assert(sinon.match.isMatcher(string));394 assert.equals(string.toString(), "typeOf(\"string\")");395 }396 },397 ".object": {398 "is typeOf object matcher": function () {399 var object = sinon.match.object;400 assert(sinon.match.isMatcher(object));401 assert.equals(object.toString(), "typeOf(\"object\")");402 }403 },404 ".func": {405 "is typeOf function matcher": function () {406 var func = sinon.match.func;407 assert(sinon.match.isMatcher(func));408 assert.equals(func.toString(), "typeOf(\"function\")");409 }410 },411 ".array": {412 "is typeOf array matcher": function () {413 var array = sinon.match.array;414 assert(sinon.match.isMatcher(array));415 assert.equals(array.toString(), "typeOf(\"array\")");416 }417 },418 ".regexp": {419 "is typeOf regexp matcher": function () {420 var regexp = sinon.match.regexp;421 assert(sinon.match.isMatcher(regexp));422 assert.equals(regexp.toString(), "typeOf(\"regexp\")");423 }424 },425 ".date": {426 "is typeOf regexp matcher": function () {427 var date = sinon.match.date;428 assert(sinon.match.isMatcher(date));429 assert.equals(date.toString(), "typeOf(\"date\")");430 }431 },432 ".or": {433 "is matcher": function () {434 var numberOrString = sinon.match.number.or(sinon.match.string);435 assert(sinon.match.isMatcher(numberOrString));436 assert.equals(numberOrString.toString(),437 "typeOf(\"number\").or(typeOf(\"string\"))");438 },439 "requires matcher argument": function () {440 assert.exception(function () {441 sinon.match.instanceOf(Error).or();442 }, "TypeError");443 },444 "will coerce argument to matcher": function () {445 var abcOrDef = sinon.match("abc").or("def");446 assert(sinon.match.isMatcher(abcOrDef));447 assert.equals(abcOrDef.toString(),448 "match(\"abc\").or(match(\"def\"))");449 },450 "returns true if either matcher matches": function () {451 var numberOrString = sinon.match.number.or(sinon.match.string);452 assert(numberOrString.test(123));453 assert(numberOrString.test("abc"));454 },455 "returns false if neither matcher matches": function () {456 var numberOrAbc = sinon.match.number.or("abc");457 assert.isFalse(numberOrAbc.test(/.+/));458 assert.isFalse(numberOrAbc.test(new Date()));459 assert.isFalse(numberOrAbc.test({}));460 },461 "can be used with undefined": function () {462 var numberOrUndef = sinon.match.number.or(undefined);463 assert(numberOrUndef.test(123));464 assert(numberOrUndef.test(undefined));465 }466 },467 ".and": {468 "is matcher": function () {469 var fooAndBar = sinon.match.has("foo").and(sinon.match.has("bar"));470 assert(sinon.match.isMatcher(fooAndBar));471 assert.equals(fooAndBar.toString(), "has(\"foo\").and(has(\"bar\"))");472 },473 "requires matcher argument": function () {474 assert.exception(function () {475 sinon.match.instanceOf(Error).and();476 }, "TypeError");477 },478 "will coerce to matcher": function () {479 var abcOrObj = sinon.match("abc").or({a:1});480 assert(sinon.match.isMatcher(abcOrObj));481 assert.equals(abcOrObj.toString(),482 "match(\"abc\").or(match(a: 1))");483 },484 "returns true if both matchers match": function () {485 var fooAndBar = sinon.match.has("foo").and({ bar: "bar" });486 assert(fooAndBar.test({ foo: "foo", bar: "bar" }));487 },488 "returns false if either matcher does not match": function () {489 var fooAndBar = sinon.match.has("foo").and(sinon.match.has("bar"));490 assert.isFalse(fooAndBar.test({ foo: "foo" }));491 assert.isFalse(fooAndBar.test({ bar: "bar" }));492 },493 "can be used with undefined": function () {494 var falsyAndUndefined = sinon.match.falsy.and(undefined);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var match = require('sinon').match;2var sinon = require('sinon');3var assert = require('assert');4var sinonTest = require('sinon-test');5sinon.test = sinonTest.configureTest(sinon);6sinon.testCase = sinonTest.configureTestCase(sinon);7describe('match.isMatcher', function () {8 it('should return true if the argument is a matcher', function () {9 assert.equal(match.isMatcher(sinon.match.string), true);10 });11});12describe('match.isMatcher', function () {13 it('should return false if the argument is not a matcher', function () {14 assert.equal(match.isMatcher(sinon.match), false);15 });16});17var match = require('sinon').match;18var sinon = require('sinon');19var assert = require('assert');20var sinonTest = require('sinon-test');21sinon.test = sinonTest.configureTest(sinon);22sinon.testCase = sinonTest.configureTestCase(sinon);23describe('match.isMatcher', function () {24 it('should return true if the argument is a matcher', function () {25 assert.equal(match.isMatcher(sinon.match.string), true);26 });27});28describe('match.isMatcher', function () {29 it('should return false if the argument is not a matcher', function () {30 assert.equal(match.isMatcher(sinon.match), false);31 });32});33var match = require('sinon').match;34var sinon = require('sinon');35var assert = require('assert');36var sinonTest = require('sinon-test');37sinon.test = sinonTest.configureTest(sinon);38sinon.testCase = sinonTest.configureTestCase(sinon);39describe('match.isMatcher', function () {40 it('should return true if the argument is a matcher', function () {41 assert.equal(match.isMatcher(sinon.match.string), true);42 });43});44describe('match.isMatcher', function () {45 it('should return false if the argument is not a matcher', function () {46 assert.equal(match.isMatcher(sinon.match), false);47 });48});49var match = require('sinon').match;50var sinon = require('sinon');51var assert = require('assert');

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var match = sinon.match;3var spy = sinon.spy();4spy(1, 2, 3);5spy(4, 5, 6);6spy(7, 8, 9);7var spyCall = spy.getCall(0);8var firstArg = spyCall.args[0];9console.log(match.isMatcher(firstArg));10console.log(match.isMatcher(1));11console.log(match.isMatcher('1'));12console.log(match.isMatcher({}));13console.log(match.isMatcher(function(){}));14console.log(match.isMatcher(true));15console.log(match.isMatcher(false));16console.log(match.isMatcher(null));17console.log(match.isMatcher(undefined));18console.log(match.isMatcher(NaN));19console.log(match.isMatcher(Infinity));20console.log(match.isMatcher(-Infinity));21console.log(match.isMatcher(0));22console.log(match.isMatcher(0.0));23console.log(match.isMatcher(0.1));24console.log(match.isMatcher(-0.1));25console.log(match.isMatcher(-0.0));26console.log(match.isMatcher([1,2,3]));27console.log(match.isMatcher([1,2,3,4]));28console.log(match.isMatcher([1,2,3,4,5]));29console.log(match.isMatcher([1,2,3,4,5,6]));30console.log(match.isMatcher([1,2,3,4,5,6,7]));31console.log(match.isMatcher([1,2,3,4,5,6,7,8]));32console.log(match.isMatcher([1,2,3,4,5,6,7,8,9]));33console.log(match.isMatcher([1,2,3,4,5,6,7,8,9,10]));34console.log(match.isMatcher([1,2,3,4,5,6,7,8,9,10,11]));35console.log(match.isMatcher([1,2,3,4,5,6,7,8,9,10,11,12]));

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var match = sinon.match;3var obj = {foo: 'bar'};4var spy = sinon.spy();5var stub = sinon.stub();6var mock = sinon.mock();7var sinon = require('sinon');8var match = sinon.match;9var obj = {foo: 'bar'};10var spy = sinon.spy();11var stub = sinon.stub();12var mock = sinon.mock();13var sinon = require('sinon');14var match = sinon.match;15var obj = {foo: 'bar'};16var spy = sinon.spy();17var stub = sinon.stub();18var mock = sinon.mock();19var sinon = require('sinon');20var match = sinon.match;21var obj = {foo: 'bar'};22var spy = sinon.spy();23var stub = sinon.stub();24var mock = sinon.mock();25var sinon = require('sinon');26var match = sinon.match;27var obj = {foo: 'bar'};28var spy = sinon.spy();29var stub = sinon.stub();30var mock = sinon.mock();31console.log(match.isMatcher(mock));

Full Screen

Using AI Code Generation

copy

Full Screen

1var match = require('sinon').match;2var sinon = require('sinon');3var spy = sinon.spy();4spy(1,2,3);5var match = require('sinon').match;6var sinon = require('sinon');7var spy = sinon.spy();8spy(1,2,3);9var match = require('sinon').match;10var sinon = require('sinon');11var stub = sinon.stub();12stub(1,2,3);13var match = require('sinon').match;14var sinon = require('sinon');15var sandbox = sinon.createSandbox();16sandbox.stub();

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var matcher = sinon.match('test');3var chai = require('chai');4var matcher = chai.match('test');5var matcher = jasmine.matchersUtil.equals('test');6var expect = require('expect.js');7var matcher = expect.match('test');8var should = require('should');9var matcher = should.match('test');10var chai = require('chai');11var chaiAsPromised = require('chai-as-promised');12chai.use(chaiAsPromised);13var matcher = chai.match('test');14var chai = require('chai');15var chaiThings = require('chai-things');16chai.use(chaiThings);17var matcher = chai.match('test');18var chai = require('chai');19var chaiJsonSchema = require('chai-json-schema');20chai.use(chaiJsonSchema);21var matcher = chai.match('test');22var chai = require('chai');23var chaiJquery = require('chai-jquery');24chai.use(chaiJquery);25var matcher = chai.match('test');

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var match = sinon.match;3var obj = {4 address: {5 }6};7var sinon = require('sinon');8var match = sinon.match;9var obj = {10 address: {11 }12};13var sinon = require('sinon');14var match = sinon.match;15var obj = {16 address: {17 }18};19var sinon = require('sinon');20var match = sinon.match;21var obj = {22 address: {23 }24};25var sinon = require('sinon');26var match = sinon.match;27var obj = {28 address: {29 }30};31match.isTypeOf('test', 'string

Full Screen

Using AI Code Generation

copy

Full Screen

1var match = require('sinon').match;2var assert = require('assert');3var sinon = require('sinon');4var myObj = {5 myMethod: function() {6 console.log('myMethod called');7 }8};9var spy = sinon.spy(myObj, 'myMethod');10myObj.myMethod();11assert(spy.calledOnce);12var match = require('sinon').match;13var assert = require('assert');14var sinon = require('sinon');15var myObj = {16 myMethod: function() {17 console.log('myMethod called');18 }19};20var spy = sinon.spy(myObj, 'myMethod');21myObj.myMethod();22assert(spy.calledOnce);23var match = require('sinon').match;24var assert = require('assert');25var sinon = require('sinon');26var myObj = {27 myMethod: function() {28 console.log('myMethod called');29 }30};31var spy = sinon.spy(myObj, 'myMethod');32myObj.myMethod();33assert(spy.calledOnce);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var match = sinon.match;3var user = {name: 'foo', age: 20};4var matcher = match(user);5var sinon = require('sinon');6var match = sinon.match;7var user = {name: 'foo', age: 20};8var matcher = match(user);9var sinon = require('sinon');10var match = sinon.match;11var user = {name: 'foo', age: 20};12var matcher = match(user);13var sinon = require('sinon');14var match = sinon.match;15var user = {name: 'foo', age: 20};16var matcher = match(user);17console.log(matcher.test({name: 'bar', age

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const match = sinon.match;3const testObject = {4};5const testObject2 = {6};7const testObject3 = {8};9const testObject4 = {10};11const testObject5 = {12};13const testObject6 = {14};15const testObject7 = {16};17const testObject8 = {18};19const testObject9 = {20};21const testObject10 = {22};23const testObject11 = {24};25const testObject12 = {26};27const testObject13 = {28};29const testObject14 = {30};31const testObject15 = {32};33const testObject16 = {34};35const testObject17 = {36};37const testObject18 = {38};39const testObject19 = {40};41const testObject20 = {42};43const testObject21 = {44};45const testObject22 = {46};47const testObject23 = {48};49const testObject24 = {50};51const testObject25 = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run sinon automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful