Permalink
Browse files

Alias reserved word with with withArgs.

  • Loading branch information...
1 parent d291a53 commit 011e20bb3a4ce40b6d48c53c7e06a27469940a12 @btipling btipling committed Feb 18, 2013
Showing with 16 additions and 2 deletions.
  1. +12 −1 example/test-spyon.js
  2. +4 −1 lib/common.js
View
13 example/test-spyon.js
@@ -85,6 +85,17 @@ exports['test_spyon_with_arguments_correct'] = function(test, assert) {
arr = ['a', 'b', null];
test.spy.on('setBar', foo);
foo.setBar(arr);
+ assert.ok(test.spy.called('setBar').withArgs(arr));
+ test.spy.clear('setBar', foo);
+ test.finish();
+};
+
+exports['test_spyon_with_arguments_alias'] = function(test, assert) {
+ var foo, arr;
+ foo = new Foo();
+ arr = ['a', 'b', null];
+ test.spy.on('setBar', foo);
+ foo.setBar(arr);
assert.ok(test.spy.called('setBar').with(arr));
test.spy.clear('setBar', foo);
test.finish();
@@ -96,7 +107,7 @@ exports['test_spyon_with_arguments_incorrect'] = function(test, assert) {
arr = ['a', 'b', null];
test.spy.on('setBar', foo);
foo.setBar(['c']);
- assert.ok(!test.spy.called('setBar').with(arr));
+ assert.ok(!test.spy.called('setBar').withArgs(arr));
test.spy.clear('setBar', foo);
test.finish();
};
View
5 lib/common.js
@@ -639,7 +639,7 @@ SpyOn.prototype.called = function (funcName) {
valueOf: function () {
return calls.length;
},
- with: function () {
+ withArgs: function () {
var i, j, match;
var args = Array.prototype.slice.call(arguments);
for (i = 0; i < calls.length; i++) {
@@ -648,6 +648,9 @@ SpyOn.prototype.called = function (funcName) {
}
}
return false;
+ },
+ with: function () {
+ return this.withArgs.apply(this, arguments);
}
}
};

0 comments on commit 011e20b

Please sign in to comment.