Simplified ExpectationFilterChain#modifyFailureMessage
This commit is contained in:
@@ -85,20 +85,29 @@ describe('ExpectationFilterChain', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#modifyFailureMessage', function() {
|
describe('#modifyFailureMessage', function() {
|
||||||
it('calls each filter with the return value of the next previously added filter', function() {
|
describe('When no filters have #modifyFailureMessage', function() {
|
||||||
|
it('returns the original message', function() {
|
||||||
|
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||||
|
chain.addFilter({});
|
||||||
|
expect(chain.modifyFailureMessage('msg')).toEqual('msg');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When some filters have #modifyFailureMessage', function() {
|
||||||
|
it('calls the first filter that has #modifyFailureMessage', function() {
|
||||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
var first = jasmine.createSpy('first').and.returnValue('first'),
|
||||||
third = jasmine.createSpy('third').and.returnValue('third'),
|
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||||
.addFilter({modifyFailureMessage: first})
|
.addFilter({modifyFailureMessage: first})
|
||||||
.addFilter({})
|
.addFilter({modifyFailureMessage: second}),
|
||||||
.addFilter({modifyFailureMessage: third}),
|
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = chain.modifyFailureMessage('original');
|
result = chain.modifyFailureMessage('original');
|
||||||
|
|
||||||
expect(first).toHaveBeenCalledWith('original');
|
expect(first).toHaveBeenCalledWith('original');
|
||||||
expect(third).toHaveBeenCalledWith('first');
|
expect(second).not.toHaveBeenCalled();
|
||||||
expect(result).toEqual('third');
|
expect(result).toEqual('first');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,15 +17,8 @@ getJasmineRequireObj().ExpectationFilterChain = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
||||||
if (this.prev_) {
|
var result = this.callFirst_('modifyFailureMessage', arguments).result;
|
||||||
msg = this.prev_.modifyFailureMessage(msg);
|
return result || msg;
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filter_ && this.filter_.modifyFailureMessage) {
|
|
||||||
msg = this.filter_.modifyFailureMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user