Pass sensible arguments in ExpectationResults
This commit is contained in:
parent
328cc89980
commit
827fd1da0e
|
@ -272,7 +272,7 @@ ul.inheritsList
|
|||
</div>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
|
@ -308,7 +308,7 @@ ul.inheritsList
|
|||
</div>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
|
@ -910,7 +910,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -341,7 +341,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -509,7 +509,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -269,33 +269,6 @@ ul.inheritsList
|
|||
|
||||
<!-- ============================== 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 ======================== -->
|
||||
|
||||
|
||||
|
@ -357,53 +330,6 @@ ul.inheritsList
|
|||
|
||||
<!-- ============================== 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 ========================= -->
|
||||
|
||||
|
@ -415,7 +341,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -702,7 +702,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -329,7 +329,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -341,7 +341,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -847,7 +847,7 @@ expect(foo.bar.callCount).toEqual(0);</pre>
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -347,7 +347,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -762,7 +762,7 @@ Jasmine environment.
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -318,7 +318,7 @@ ul.inheritsList
|
|||
<!-- ============================== footer ================================= -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -536,7 +536,7 @@ jasmine.version_= {
|
|||
"major": 0,
|
||||
"minor": 10,
|
||||
"build": 0,
|
||||
"revision": 1256870877
|
||||
"revision": 1256873610
|
||||
};
|
||||
/**
|
||||
* @namespace
|
||||
|
@ -1003,18 +1003,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that compares the actual to the expected using ===.
|
||||
*
|
||||
* @param expected
|
||||
*/
|
||||
|
||||
|
||||
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
||||
jasmine.Matchers.prototype[matcherName] = function () {
|
||||
jasmine.util.extend(this, options);
|
||||
var expected = jasmine.util.argsToArray(arguments);
|
||||
var args = [this.actual].concat(expected);
|
||||
var matcherArgs = jasmine.util.argsToArray(arguments);
|
||||
var args = [this.actual].concat(matcherArgs);
|
||||
var result = options.test.apply(this, args);
|
||||
var message;
|
||||
if (!result) {
|
||||
|
@ -1023,7 +1016,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) {
|
|||
var expectationResult = new jasmine.ExpectationResult({
|
||||
matcherName: matcherName,
|
||||
passed: result,
|
||||
expected: expected,
|
||||
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
|
||||
actual: this.actual,
|
||||
message: message
|
||||
});
|
||||
|
@ -1099,7 +1092,7 @@ jasmine.Matchers.addMatcher('toMatch', {
|
|||
return new RegExp(expected).test(actual);
|
||||
},
|
||||
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));
|
||||
},
|
||||
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() {
|
||||
var matcher = match('a');
|
||||
matcher.toEqual('b');
|
||||
var actual = 'a';
|
||||
var matcher = match(actual);
|
||||
var expected = 'b';
|
||||
matcher.toEqual(expected);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toEqual");
|
||||
expect(result.passed()).toEqual(false);
|
||||
expect(result.message).toMatch("a");
|
||||
expect(result.message).toMatch("b");
|
||||
expect(result.expected).toEqual(["b"]);
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.message).toMatch(jasmine.pp(actual));
|
||||
expect(result.message).toMatch(jasmine.pp(expected));
|
||||
expect(result.expected).toEqual(expected);
|
||||
expect(result.actual).toEqual(actual);
|
||||
});
|
||||
|
||||
it("toNotEqual to build an Expectation Result", function() {
|
||||
var matcher = match('a');
|
||||
matcher.toNotEqual('a');
|
||||
var str = 'a';
|
||||
var matcher = match(str);
|
||||
matcher.toNotEqual(str);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toNotEqual");
|
||||
expect(result.passed()).toEqual(false);
|
||||
expect(result.message).toMatch(/a/);
|
||||
expect(result.message).toMatch(/not/);
|
||||
expect(result.expected).toEqual(["a"]);
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.message).toMatch(jasmine.pp(str));
|
||||
expect(result.message).toMatch('not');
|
||||
expect(result.expected).toEqual(str);
|
||||
expect(result.actual).toEqual(str);
|
||||
});
|
||||
|
||||
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.message).toMatch(jasmine.pp(actual));
|
||||
expect(result.message).toMatch(jasmine.pp(expected));
|
||||
expect(result.expected).toEqual([expected]);
|
||||
expect(result.expected).toEqual(expected);
|
||||
expect(result.actual).toEqual(actual);
|
||||
});
|
||||
|
||||
|
@ -114,7 +117,7 @@ describe("jasmine.Matchers", function() {
|
|||
expect(result.matcherName).toEqual("toNotBe");
|
||||
expect(result.passed()).toEqual(false);
|
||||
expect(result.message).toMatch(str);
|
||||
expect(result.expected).toEqual([str]);
|
||||
expect(result.expected).toEqual(str);
|
||||
expect(result.actual).toEqual(str);
|
||||
});
|
||||
|
||||
|
@ -133,57 +136,68 @@ describe("jasmine.Matchers", function() {
|
|||
});
|
||||
|
||||
it("toMatch w/ RegExp to build an ExpectationResult", function() {
|
||||
var matcher = match('a');
|
||||
matcher.toMatch(/b/);
|
||||
var actual = 'a';
|
||||
var matcher = match(actual);
|
||||
var expected = /b/;
|
||||
matcher.toMatch(expected);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toMatch");
|
||||
expect(result.passed()).toEqual(false);
|
||||
expect(result.message).toEqual("a does not match the regular expression /b/");
|
||||
expect(result.expected.toString()).toEqual("/b/");
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.message).toMatch(jasmine.pp(actual));
|
||||
expect(result.message).toMatch(expected.toString());
|
||||
expect(result.expected).toEqual(expected);
|
||||
expect(result.actual).toEqual(actual);
|
||||
});
|
||||
|
||||
it("toMatch w/ String to build an ExpectationResult", function() {
|
||||
var matcher = match('a');
|
||||
matcher.toMatch("b");
|
||||
var actual = 'a';
|
||||
var matcher = match(actual);
|
||||
var expected = 'b';
|
||||
matcher.toMatch(expected);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toMatch");
|
||||
expect(result.passed()).toEqual(false);
|
||||
expect(result.message).toEqual("a does not match the regular expression /b/");
|
||||
expect(result.expected.toString()).toEqual("b");
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.message).toMatch(jasmine.pp(actual));
|
||||
expect(result.message).toMatch(new RegExp(expected).toString());
|
||||
expect(result.expected).toEqual(expected);
|
||||
expect(result.actual).toEqual(actual);
|
||||
});
|
||||
|
||||
it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
|
||||
var matcher = match('a');
|
||||
matcher.toNotMatch(/a/);
|
||||
var actual = 'a';
|
||||
var matcher = match(actual);
|
||||
var expected = /a/;
|
||||
matcher.toNotMatch(expected);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toNotMatch");
|
||||
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.expected.toString()).toEqual("/a/");
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.expected).toEqual(expected);
|
||||
expect(result.actual).toEqual(actual);
|
||||
});
|
||||
|
||||
it("toNotMatch w/ String to build an ExpectationResult", function() {
|
||||
var matcher = match('a');
|
||||
matcher.toNotMatch('a');
|
||||
var str = 'a';
|
||||
var matcher = match(str);
|
||||
matcher.toNotMatch(str);
|
||||
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
|
||||
expect(result.matcherName).toEqual("toNotMatch");
|
||||
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.expected.toString()).toEqual('a');
|
||||
expect(result.actual).toEqual("a");
|
||||
expect(result.expected).toEqual(str);
|
||||
expect(result.actual).toEqual(str);
|
||||
});
|
||||
|
||||
it("toBeDefined", function() {
|
||||
|
@ -361,7 +375,7 @@ describe("jasmine.Matchers", function() {
|
|||
expect(result.message).toMatch('contain');
|
||||
expect(result.message).toMatch(jasmine.pp(expected));
|
||||
expect(result.actual).toEqual(actual);
|
||||
expect(result.expected).toEqual([expected]);
|
||||
expect(result.expected).toEqual(expected);
|
||||
});
|
||||
|
||||
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(jasmine.pp(expected));
|
||||
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() {
|
||||
|
@ -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(expected));
|
||||
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() {
|
||||
|
@ -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(expected));
|
||||
expect(result.actual).toEqual(actual);
|
||||
expect(result.expected).toEqual([expected]);
|
||||
expect(result.expected).toEqual(expected);
|
||||
});
|
||||
|
||||
it("toThrow", function() {
|
||||
|
@ -443,12 +457,13 @@ describe("jasmine.Matchers", function() {
|
|||
|
||||
var exception;
|
||||
try {
|
||||
(function (){
|
||||
new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
|
||||
})();
|
||||
(function () {
|
||||
new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
|
||||
})();
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
};
|
||||
}
|
||||
;
|
||||
expect(exception).toBeDefined();
|
||||
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() {
|
||||
var TestClass;
|
||||
beforeEach(function() {
|
||||
TestClass = { someFunction: function() {
|
||||
} };
|
||||
});
|
||||
|
||||
it('should always show an error if the actual is not a spy', function () {
|
||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
expect(result.message).toEqual("Actual is not a spy.");
|
||||
describe('without spies', function() {
|
||||
it('should always show an error', function () {
|
||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
expect(result.message).toEqual("Actual is not a spy.");
|
||||
|
||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
||||
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
expect(result.message).toEqual("Actual is not a spy.");
|
||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
|
||||
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
expect(result.message).toEqual("Actual is not a spy.");
|
||||
});
|
||||
});
|
||||
|
||||
it("should work for spys", function() {
|
||||
TestClass.someFunction = jasmine.createSpy("My spy");
|
||||
describe('with spies', function () {
|
||||
|
||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
|
||||
beforeEach(function () {
|
||||
TestClass.someFunction = jasmine.createSpy("My spy");
|
||||
});
|
||||
|
||||
TestClass.someFunction();
|
||||
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);
|
||||
it("should track if it was called", function() {
|
||||
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
|
||||
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
|
||||
|
||||
TestClass.someFunction('a', 'b', 'c');
|
||||
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
|
||||
TestClass.someFunction();
|
||||
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);
|
||||
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
||||
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
expect(result.passed()).toEqual(false);
|
||||
it('should return true if it was called with the expected args', function() {
|
||||
TestClass.someFunction('a', 'b', 'c');
|
||||
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
|
||||
});
|
||||
|
||||
TestClass.someFunction.reset();
|
||||
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);
|
||||
it('should return false if it was not called with the expected args', function() {
|
||||
TestClass.someFunction('a', 'b', 'c');
|
||||
var expected = match(TestClass.someFunction);
|
||||
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
||||
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
|
||||
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 () {
|
||||
var TestClass;
|
||||
beforeEach(function() {
|
||||
|
@ -561,4 +590,5 @@ describe("jasmine.Matchers", function() {
|
|||
expect(result.expected).toEqual(['a','b']);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
;
|
||||
|
|
|
@ -24,18 +24,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that compares the actual to the expected using ===.
|
||||
*
|
||||
* @param expected
|
||||
*/
|
||||
|
||||
|
||||
jasmine.Matchers.addMatcher = function(matcherName, options) {
|
||||
jasmine.Matchers.prototype[matcherName] = function () {
|
||||
jasmine.util.extend(this, options);
|
||||
var expected = jasmine.util.argsToArray(arguments);
|
||||
var args = [this.actual].concat(expected);
|
||||
var matcherArgs = jasmine.util.argsToArray(arguments);
|
||||
var args = [this.actual].concat(matcherArgs);
|
||||
var result = options.test.apply(this, args);
|
||||
var message;
|
||||
if (!result) {
|
||||
|
@ -44,7 +37,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) {
|
|||
var expectationResult = new jasmine.ExpectationResult({
|
||||
matcherName: matcherName,
|
||||
passed: result,
|
||||
expected: expected,
|
||||
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
|
||||
actual: this.actual,
|
||||
message: message
|
||||
});
|
||||
|
@ -120,7 +113,7 @@ jasmine.Matchers.addMatcher('toMatch', {
|
|||
return new RegExp(expected).test(actual);
|
||||
},
|
||||
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));
|
||||
},
|
||||
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