Fix wasCalledWith matcher.

This commit is contained in:
Christian Williams 2009-11-12 15:03:55 -05:00
parent 3b92b9bb79
commit 98e86817bf
2 changed files with 23 additions and 21 deletions

View File

@ -535,28 +535,30 @@ describe("jasmine.Matchers", function() {
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false); expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
}); });
it('should return true if it was called with the expected args', function() { describe("wasCalledWith", function() {
TestClass.someFunction('a', 'b', 'c'); it('wasCalledWith should return true if it was called with the expected args', function() {
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true); TestClass.someFunction('a', 'b', 'c');
}); expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
});
it('should return false if it was not called with the expected args', function() { it('should return false if it was not called with the expected args', function() {
TestClass.someFunction('a', 'b', 'c'); TestClass.someFunction('a', 'b', 'c');
var expected = match(TestClass.someFunction); var expected = match(TestClass.someFunction);
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false); expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.passed()).toEqual(false); expect(result.passed()).toEqual(false);
expect(result.expected).toEqual(['c', 'b', 'a']); expect(result.expected).toEqual(['c', 'b', 'a']);
expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
}); });
it('should allow matches across multiple calls', function() { it('should allow matches across multiple calls', function() {
var expected = match(TestClass.someFunction); var expected = match(TestClass.someFunction);
TestClass.someFunction('a', 'b', 'c'); TestClass.someFunction('a', 'b', 'c');
TestClass.someFunction('d', 'e', 'f'); TestClass.someFunction('d', 'e', 'f');
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true); expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true); expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false); expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
});
}); });
}); });
}); });

View File

@ -224,7 +224,7 @@ jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.matcherFn_('wasCalle
throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
} }
return this.env.contains_(this.actual.argsForCall, arguments); return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
}, },
message: function() { message: function() {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + this.actual.argsForCall; return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + this.actual.argsForCall;