diff --git a/spec/core/ExpectationFilterChainSpec.js b/spec/core/ExpectationFilterChainSpec.js index 532af0c5..195fbe27 100644 --- a/spec/core/ExpectationFilterChainSpec.js +++ b/spec/core/ExpectationFilterChainSpec.js @@ -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'); + }); }); }); }); diff --git a/src/core/ExpectationFilterChain.js b/src/core/ExpectationFilterChain.js index 99cab978..83018bd6 100644 --- a/src/core/ExpectationFilterChain.js +++ b/src/core/ExpectationFilterChain.js @@ -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) {