MCPcopy
hub / github.com/Semantic-Org/Semantic-UI / match

Function match

test/helpers/sinon.js:1093–1155  ·  view source on GitHub ↗
(expectation, message)

Source from the content-addressed store, hash-verified

1091 };
1092
1093 var match = function (expectation, message) {
1094 var m = sinon.create(matcher);
1095 var type = sinon.typeOf(expectation);
1096 switch (type) {
1097 case "object":
1098 if (typeof expectation.test === "function") {
1099 m.test = function (actual) {
1100 return expectation.test(actual) === true;
1101 };
1102 m.message = "match(" + sinon.functionName(expectation.test) + ")";
1103 return m;
1104 }
1105 var str = [];
1106 for (var key in expectation) {
1107 if (expectation.hasOwnProperty(key)) {
1108 str.push(key + ": " + expectation[key]);
1109 }
1110 }
1111 m.test = function (actual) {
1112 return matchObject(expectation, actual);
1113 };
1114 m.message = "match(" + str.join(", ") + ")";
1115 break;
1116 case "number":
1117 m.test = function (actual) {
1118 return expectation == actual;
1119 };
1120 break;
1121 case "string":
1122 m.test = function (actual) {
1123 if (typeof actual !== "string") {
1124 return false;
1125 }
1126 return actual.indexOf(expectation) !== -1;
1127 };
1128 m.message = "match(\"" + expectation + "\")";
1129 break;
1130 case "regexp":
1131 m.test = function (actual) {
1132 if (typeof actual !== "string") {
1133 return false;
1134 }
1135 return expectation.test(actual);
1136 };
1137 break;
1138 case "function":
1139 m.test = expectation;
1140 if (message) {
1141 m.message = message;
1142 } else {
1143 m.message = "match(" + sinon.functionName(expectation) + ")";
1144 }
1145 break;
1146 default:
1147 m.test = function (actual) {
1148 return sinon.deepEqual(expectation, actual);
1149 };
1150 }

Callers 3

arrayContainsFunction · 0.85
sinon.jsFile · 0.85
createPropertyMatcherFunction · 0.85

Calls 2

matchObjectFunction · 0.85
matchOneFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…