Simplified ExpectationFilterChain#modifyFailureMessage
This commit is contained in:
@@ -85,20 +85,29 @@ describe('ExpectationFilterChain', 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'),
|
||||
third = jasmine.createSpy('third').and.returnValue('third'),
|
||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({modifyFailureMessage: first})
|
||||
.addFilter({})
|
||||
.addFilter({modifyFailureMessage: third}),
|
||||
.addFilter({modifyFailureMessage: second}),
|
||||
result;
|
||||
|
||||
result = chain.modifyFailureMessage('original');
|
||||
|
||||
expect(first).toHaveBeenCalledWith('original');
|
||||
expect(third).toHaveBeenCalledWith('first');
|
||||
expect(result).toEqual('third');
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
expect(result).toEqual('first');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,15 +17,8 @@ getJasmineRequireObj().ExpectationFilterChain = function() {
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
||||
if (this.prev_) {
|
||||
msg = this.prev_.modifyFailureMessage(msg);
|
||||
}
|
||||
|
||||
if (this.filter_ && this.filter_.modifyFailureMessage) {
|
||||
msg = this.filter_.modifyFailureMessage(msg);
|
||||
}
|
||||
|
||||
return msg;
|
||||
var result = this.callFirst_('modifyFailureMessage', arguments).result;
|
||||
return result || msg;
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
||||
|
||||
Reference in New Issue
Block a user