Pass sensible arguments in ExpectationResults
This commit is contained in:
parent
328cc89980
commit
827fd1da0e
@ -272,7 +272,7 @@ ul.inheritsList
|
|||||||
</div>
|
</div>
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -308,7 +308,7 @@ ul.inheritsList
|
|||||||
</div>
|
</div>
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -910,7 +910,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -341,7 +341,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -509,7 +509,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -269,33 +269,6 @@ ul.inheritsList
|
|||||||
|
|
||||||
<!-- ============================== methods summary ======================== -->
|
<!-- ============================== methods summary ======================== -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<table class="summaryTable" cellspacing="0" summary="A summary of the methods documented in the class jasmine.Matchers.">
|
|
||||||
<caption>Method Summary</caption>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Method Attributes</th>
|
|
||||||
<th scope="col">Method Name and Description</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="attributes"><static> </td>
|
|
||||||
<td class="nameDescription">
|
|
||||||
<div class="fixedFont">jasmine.Matchers.<b><a href="../symbols/jasmine.Matchers.html#.addMatcher">addMatcher</a></b>(expected, options)
|
|
||||||
</div>
|
|
||||||
<div class="description">Matcher that compares the actual to the expected using ===.</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ============================== events summary ======================== -->
|
<!-- ============================== events summary ======================== -->
|
||||||
|
|
||||||
|
|
||||||
@ -357,53 +330,6 @@ ul.inheritsList
|
|||||||
|
|
||||||
<!-- ============================== method details ========================= -->
|
<!-- ============================== method details ========================= -->
|
||||||
|
|
||||||
<div class="sectionTitle">
|
|
||||||
Method Detail
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<a name=".addMatcher"> </a>
|
|
||||||
<div class="fixedFont"><static>
|
|
||||||
|
|
||||||
|
|
||||||
<span class="light">jasmine.Matchers.</span><b>addMatcher</b>(expected, options)
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="description">
|
|
||||||
Matcher that compares the actual to the expected using ===.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dl class="detailList">
|
|
||||||
<dt class="heading">Parameters:</dt>
|
|
||||||
|
|
||||||
<dt>
|
|
||||||
<b>expected</b>
|
|
||||||
|
|
||||||
</dt>
|
|
||||||
<dd></dd>
|
|
||||||
|
|
||||||
<dt>
|
|
||||||
<b>options</b>
|
|
||||||
|
|
||||||
</dt>
|
|
||||||
<dd></dd>
|
|
||||||
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ============================== event details ========================= -->
|
<!-- ============================== event details ========================= -->
|
||||||
|
|
||||||
@ -415,7 +341,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -702,7 +702,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -329,7 +329,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -341,7 +341,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -847,7 +847,7 @@ expect(foo.bar.callCount).toEqual(0);</pre>
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -347,7 +347,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -762,7 +762,7 @@ Jasmine environment.
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||||||
<!-- ============================== footer ================================= -->
|
<!-- ============================== footer ================================= -->
|
||||||
<div class="fineprint" style="clear:both">
|
<div class="fineprint" style="clear:both">
|
||||||
|
|
||||||
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
|
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -536,7 +536,7 @@ jasmine.version_= {
|
|||||||
"major": 0,
|
"major": 0,
|
||||||
"minor": 10,
|
"minor": 10,
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"revision": 1256870877
|
"revision": 1256873610
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
@ -1003,18 +1003,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Matcher that compares the actual to the expected using ===.
|
|
||||||
*
|
|
||||||
* @param expected
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
||||||
jasmine.Matchers.prototype[matcherName] = function () {
|
jasmine.Matchers.prototype[matcherName] = function () {
|
||||||
jasmine.util.extend(this, options);
|
jasmine.util.extend(this, options);
|
||||||
var expected = jasmine.util.argsToArray(arguments);
|
var matcherArgs = jasmine.util.argsToArray(arguments);
|
||||||
var args = [this.actual].concat(expected);
|
var args = [this.actual].concat(matcherArgs);
|
||||||
var result = options.test.apply(this, args);
|
var result = options.test.apply(this, args);
|
||||||
var message;
|
var message;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@ -1023,7 +1016,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) {
|
|||||||
var expectationResult = new jasmine.ExpectationResult({
|
var expectationResult = new jasmine.ExpectationResult({
|
||||||
matcherName: matcherName,
|
matcherName: matcherName,
|
||||||
passed: result,
|
passed: result,
|
||||||
expected: expected,
|
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
|
||||||
actual: this.actual,
|
actual: this.actual,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
@ -1099,7 +1092,7 @@ jasmine.Matchers.addMatcher('toMatch', {
|
|||||||
return new RegExp(expected).test(actual);
|
return new RegExp(expected).test(actual);
|
||||||
},
|
},
|
||||||
message: function(actual, expected) {
|
message: function(actual, expected) {
|
||||||
return actual + " does not match the regular expression " + new RegExp(expected).toString();
|
return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1113,7 +1106,7 @@ jasmine.Matchers.addMatcher('toNotMatch', {
|
|||||||
return !(new RegExp(expected).test(actual));
|
return !(new RegExp(expected).test(actual));
|
||||||
},
|
},
|
||||||
message: function(actual, expected) {
|
message: function(actual, expected) {
|
||||||
return actual + " should not match " + new RegExp(expected).toString();
|
return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,31 +48,34 @@ describe("jasmine.Matchers", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("toEqual to build an Expectation Result", function() {
|
it("toEqual to build an Expectation Result", function() {
|
||||||
var matcher = match('a');
|
var actual = 'a';
|
||||||
matcher.toEqual('b');
|
var matcher = match(actual);
|
||||||
|
var expected = 'b';
|
||||||
|
matcher.toEqual(expected);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toEqual");
|
expect(result.matcherName).toEqual("toEqual");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch("a");
|
expect(result.message).toMatch(jasmine.pp(actual));
|
||||||
expect(result.message).toMatch("b");
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.expected).toEqual(["b"]);
|
expect(result.expected).toEqual(expected);
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.actual).toEqual(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toNotEqual to build an Expectation Result", function() {
|
it("toNotEqual to build an Expectation Result", function() {
|
||||||
var matcher = match('a');
|
var str = 'a';
|
||||||
matcher.toNotEqual('a');
|
var matcher = match(str);
|
||||||
|
matcher.toNotEqual(str);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toNotEqual");
|
expect(result.matcherName).toEqual("toNotEqual");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch(/a/);
|
expect(result.message).toMatch(jasmine.pp(str));
|
||||||
expect(result.message).toMatch(/not/);
|
expect(result.message).toMatch('not');
|
||||||
expect(result.expected).toEqual(["a"]);
|
expect(result.expected).toEqual(str);
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.actual).toEqual(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toBe should return true only if the expected and actual items === each other', function() {
|
it('toBe should return true only if the expected and actual items === each other', function() {
|
||||||
@ -100,7 +103,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch(jasmine.pp(actual));
|
expect(result.message).toMatch(jasmine.pp(actual));
|
||||||
expect(result.message).toMatch(jasmine.pp(expected));
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.expected).toEqual([expected]);
|
expect(result.expected).toEqual(expected);
|
||||||
expect(result.actual).toEqual(actual);
|
expect(result.actual).toEqual(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -114,7 +117,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.matcherName).toEqual("toNotBe");
|
expect(result.matcherName).toEqual("toNotBe");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch(str);
|
expect(result.message).toMatch(str);
|
||||||
expect(result.expected).toEqual([str]);
|
expect(result.expected).toEqual(str);
|
||||||
expect(result.actual).toEqual(str);
|
expect(result.actual).toEqual(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -133,57 +136,68 @@ describe("jasmine.Matchers", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("toMatch w/ RegExp to build an ExpectationResult", function() {
|
it("toMatch w/ RegExp to build an ExpectationResult", function() {
|
||||||
var matcher = match('a');
|
var actual = 'a';
|
||||||
matcher.toMatch(/b/);
|
var matcher = match(actual);
|
||||||
|
var expected = /b/;
|
||||||
|
matcher.toMatch(expected);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toMatch");
|
expect(result.matcherName).toEqual("toMatch");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toEqual("a does not match the regular expression /b/");
|
expect(result.message).toMatch(jasmine.pp(actual));
|
||||||
expect(result.expected.toString()).toEqual("/b/");
|
expect(result.message).toMatch(expected.toString());
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.expected).toEqual(expected);
|
||||||
|
expect(result.actual).toEqual(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toMatch w/ String to build an ExpectationResult", function() {
|
it("toMatch w/ String to build an ExpectationResult", function() {
|
||||||
var matcher = match('a');
|
var actual = 'a';
|
||||||
matcher.toMatch("b");
|
var matcher = match(actual);
|
||||||
|
var expected = 'b';
|
||||||
|
matcher.toMatch(expected);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toMatch");
|
expect(result.matcherName).toEqual("toMatch");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toEqual("a does not match the regular expression /b/");
|
expect(result.message).toMatch(jasmine.pp(actual));
|
||||||
expect(result.expected.toString()).toEqual("b");
|
expect(result.message).toMatch(new RegExp(expected).toString());
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.expected).toEqual(expected);
|
||||||
|
expect(result.actual).toEqual(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
|
it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
|
||||||
var matcher = match('a');
|
var actual = 'a';
|
||||||
matcher.toNotMatch(/a/);
|
var matcher = match(actual);
|
||||||
|
var expected = /a/;
|
||||||
|
matcher.toNotMatch(expected);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toNotMatch");
|
expect(result.matcherName).toEqual("toNotMatch");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch("/a/");
|
expect(result.message).toMatch(expected.toString());
|
||||||
|
expect(result.message).toMatch(jasmine.pp(actual));
|
||||||
expect(result.message).toMatch("not");
|
expect(result.message).toMatch("not");
|
||||||
expect(result.expected.toString()).toEqual("/a/");
|
expect(result.expected).toEqual(expected);
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.actual).toEqual(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toNotMatch w/ String to build an ExpectationResult", function() {
|
it("toNotMatch w/ String to build an ExpectationResult", function() {
|
||||||
var matcher = match('a');
|
var str = 'a';
|
||||||
matcher.toNotMatch('a');
|
var matcher = match(str);
|
||||||
|
matcher.toNotMatch(str);
|
||||||
|
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
|
|
||||||
expect(result.matcherName).toEqual("toNotMatch");
|
expect(result.matcherName).toEqual("toNotMatch");
|
||||||
expect(result.passed()).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
expect(result.message).toMatch("/a/");
|
expect(result.message).toMatch(jasmine.pp(str));
|
||||||
|
expect(result.message).toMatch(new RegExp(str).toString());
|
||||||
expect(result.message).toMatch("not");
|
expect(result.message).toMatch("not");
|
||||||
expect(result.expected.toString()).toEqual('a');
|
expect(result.expected).toEqual(str);
|
||||||
expect(result.actual).toEqual("a");
|
expect(result.actual).toEqual(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toBeDefined", function() {
|
it("toBeDefined", function() {
|
||||||
@ -361,7 +375,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.message).toMatch('contain');
|
expect(result.message).toMatch('contain');
|
||||||
expect(result.message).toMatch(jasmine.pp(expected));
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.actual).toEqual(actual);
|
expect(result.actual).toEqual(actual);
|
||||||
expect(result.expected).toEqual([expected]);
|
expect(result.expected).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toNotContain to build an ExpectationResult", function() {
|
it("toNotContain to build an ExpectationResult", function() {
|
||||||
@ -378,7 +392,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.message).toMatch('not contain');
|
expect(result.message).toMatch('not contain');
|
||||||
expect(result.message).toMatch(jasmine.pp(expected));
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.actual).toEqual(actual);
|
expect(result.actual).toEqual(actual);
|
||||||
expect(result.expected).toEqual([expected]);
|
expect(result.expected).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toBeLessThan should pass if actual is less than expected", function() {
|
it("toBeLessThan should pass if actual is less than expected", function() {
|
||||||
@ -400,7 +414,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
|
expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
|
||||||
expect(result.message).toMatch(jasmine.pp(expected));
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.actual).toEqual(actual);
|
expect(result.actual).toEqual(actual);
|
||||||
expect(result.expected).toEqual([expected]);
|
expect(result.expected).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toBeGreaterThan should pass if actual is greater than expected", function() {
|
it("toBeGreaterThan should pass if actual is greater than expected", function() {
|
||||||
@ -422,7 +436,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
|
expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
|
||||||
expect(result.message).toMatch(jasmine.pp(expected));
|
expect(result.message).toMatch(jasmine.pp(expected));
|
||||||
expect(result.actual).toEqual(actual);
|
expect(result.actual).toEqual(actual);
|
||||||
expect(result.expected).toEqual([expected]);
|
expect(result.expected).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toThrow", function() {
|
it("toThrow", function() {
|
||||||
@ -443,12 +457,13 @@ describe("jasmine.Matchers", function() {
|
|||||||
|
|
||||||
var exception;
|
var exception;
|
||||||
try {
|
try {
|
||||||
(function (){
|
(function () {
|
||||||
new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
|
new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
|
||||||
})();
|
})();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
};
|
}
|
||||||
|
;
|
||||||
expect(exception).toBeDefined();
|
expect(exception).toBeDefined();
|
||||||
expect(exception.message).toEqual('Actual is not a function');
|
expect(exception.message).toEqual('Actual is not a function');
|
||||||
|
|
||||||
@ -461,55 +476,69 @@ describe("jasmine.Matchers", function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var spyMatch = function(value, spec) {
|
|
||||||
return new jasmine.Matchers(env, value, spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("wasCalled, wasNotCalled, wasCalledWith", function() {
|
describe("wasCalled, wasNotCalled, wasCalledWith", function() {
|
||||||
var TestClass;
|
var TestClass;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
TestClass = { someFunction: function() {
|
TestClass = { someFunction: function() {
|
||||||
} };
|
} };
|
||||||
});
|
});
|
||||||
|
describe('without spies', function() {
|
||||||
it('should always show an error if the actual is not a spy', function () {
|
it('should always show an error', function () {
|
||||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
expect(result.message).toEqual("Actual is not a spy.");
|
expect(result.message).toEqual("Actual is not a spy.");
|
||||||
|
|
||||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
||||||
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
expect(result.message).toEqual("Actual is not a spy.");
|
expect(result.message).toEqual("Actual is not a spy.");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work for spys", function() {
|
describe('with spies', function () {
|
||||||
TestClass.someFunction = jasmine.createSpy("My spy");
|
|
||||||
|
|
||||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
beforeEach(function () {
|
||||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
|
TestClass.someFunction = jasmine.createSpy("My spy");
|
||||||
|
});
|
||||||
|
|
||||||
TestClass.someFunction();
|
it("should track if it was called", function() {
|
||||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(true);
|
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||||
expect(function () { match(TestClass.someFunction).wasCalled('some arg');}).toThrow('wasCalled does not take arguments, use wasCalledWith');
|
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
|
||||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
|
||||||
|
|
||||||
TestClass.someFunction('a', 'b', 'c');
|
TestClass.someFunction();
|
||||||
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
|
expect(match(TestClass.someFunction).wasCalled()).toEqual(true);
|
||||||
|
expect(function () {
|
||||||
|
match(TestClass.someFunction).wasCalled('some arg');
|
||||||
|
}).toThrow('wasCalled does not take arguments, use wasCalledWith');
|
||||||
|
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
var expected = match(TestClass.someFunction);
|
it('should return true if it was called with the expected args', function() {
|
||||||
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
TestClass.someFunction('a', 'b', 'c');
|
||||||
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
|
||||||
expect(result.passed()).toEqual(false);
|
});
|
||||||
|
|
||||||
TestClass.someFunction.reset();
|
it('should return false if it was not called with the expected args', function() {
|
||||||
TestClass.someFunction('a', 'b', 'c');
|
TestClass.someFunction('a', 'b', 'c');
|
||||||
TestClass.someFunction('d', 'e', 'f');
|
var expected = match(TestClass.someFunction);
|
||||||
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
|
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
||||||
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
|
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||||
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
|
expect(result.passed()).toEqual(false);
|
||||||
|
expect(result.expected).toEqual(['c', 'b', 'a']);
|
||||||
|
expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow matches across multiple calls', function() {
|
||||||
|
var expected = match(TestClass.someFunction);
|
||||||
|
TestClass.someFunction('a', 'b', 'c');
|
||||||
|
TestClass.someFunction('d', 'e', 'f');
|
||||||
|
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
|
||||||
|
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
|
||||||
|
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("wasCalledWith to build an ExpectationResult", function () {
|
describe("wasCalledWith to build an ExpectationResult", function () {
|
||||||
var TestClass;
|
var TestClass;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
@ -561,4 +590,5 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect(result.expected).toEqual(['a','b']);
|
expect(result.expected).toEqual(['a','b']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
@ -24,18 +24,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Matcher that compares the actual to the expected using ===.
|
|
||||||
*
|
|
||||||
* @param expected
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
||||||
jasmine.Matchers.prototype[matcherName] = function () {
|
jasmine.Matchers.prototype[matcherName] = function () {
|
||||||
jasmine.util.extend(this, options);
|
jasmine.util.extend(this, options);
|
||||||
var expected = jasmine.util.argsToArray(arguments);
|
var matcherArgs = jasmine.util.argsToArray(arguments);
|
||||||
var args = [this.actual].concat(expected);
|
var args = [this.actual].concat(matcherArgs);
|
||||||
var result = options.test.apply(this, args);
|
var result = options.test.apply(this, args);
|
||||||
var message;
|
var message;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@ -44,7 +37,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) {
|
|||||||
var expectationResult = new jasmine.ExpectationResult({
|
var expectationResult = new jasmine.ExpectationResult({
|
||||||
matcherName: matcherName,
|
matcherName: matcherName,
|
||||||
passed: result,
|
passed: result,
|
||||||
expected: expected,
|
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
|
||||||
actual: this.actual,
|
actual: this.actual,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
@ -120,7 +113,7 @@ jasmine.Matchers.addMatcher('toMatch', {
|
|||||||
return new RegExp(expected).test(actual);
|
return new RegExp(expected).test(actual);
|
||||||
},
|
},
|
||||||
message: function(actual, expected) {
|
message: function(actual, expected) {
|
||||||
return actual + " does not match the regular expression " + new RegExp(expected).toString();
|
return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -134,7 +127,7 @@ jasmine.Matchers.addMatcher('toNotMatch', {
|
|||||||
return !(new RegExp(expected).test(actual));
|
return !(new RegExp(expected).test(actual));
|
||||||
},
|
},
|
||||||
message: function(actual, expected) {
|
message: function(actual, expected) {
|
||||||
return actual + " should not match " + new RegExp(expected).toString();
|
return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user