Simplified ExpectationFilterChain#modifyFailureMessage

This commit is contained in:
Steve Gravrock
2018-06-09 12:34:30 -07:00
parent 0842a80c68
commit ac07c9ea97
2 changed files with 17 additions and 15 deletions

View File

@@ -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');
});
});
});
});