Use custom equality testers in Spy#withArgs

Fixes #1836.
This commit is contained in:
Steve Gravrock
2021-11-15 18:30:43 -08:00
parent 8e74529631
commit 2a049015b0
6 changed files with 152 additions and 61 deletions

View File

@@ -231,7 +231,7 @@ describe('Spies', function() {
expect(spy('baz', 'grault', 'waldo')).toEqual(42);
});
it('uses custom equality testers when selecting a strategy', function() {
it('uses asymmetric equality testers when selecting a strategy', function() {
var spy = env.createSpy('foo');
spy.and.returnValue(42);
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
@@ -240,6 +240,23 @@ describe('Spies', function() {
expect(spy({})).toEqual(42);
});
it('uses the provided matchersUtil selecting a strategy', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [
function(a, b) {
if ((a === 'bar' && b === 'baz') || (a === 'baz' && b === 'bar')) {
return true;
}
}
]
});
const spy = new jasmineUnderTest.Spy('aSpy', matchersUtil);
spy.and.returnValue('default strategy return value');
spy.withArgs('bar').and.returnValue('custom strategy return value');
expect(spy('foo')).toEqual('default strategy return value');
expect(spy('baz')).toEqual('custom strategy return value');
});
it('can reconfigure an argument-specific strategy', function() {
var spy = env.createSpy('foo');
spy.withArgs('foo').and.returnValue(42);