Made ExpectationFilterChain immutable
This commit is contained in:
@@ -1,4 +1,32 @@
|
||||
describe('ExpectationFilterChainSpec', function() {
|
||||
describe('ExpectationFilterChain', function() {
|
||||
describe('#addFilter', function() {
|
||||
it('returns a new filter chain with the added filter', function() {
|
||||
var first = jasmine.createSpy('first'),
|
||||
second = jasmine.createSpy('second'),
|
||||
orig = new jasmineUnderTest.ExpectationFilterChain({
|
||||
modifyFailureMessage: first
|
||||
}),
|
||||
added = orig.addFilter({selectComparisonFunc: second});
|
||||
|
||||
added.modifyFailureMessage();
|
||||
expect(first).toHaveBeenCalled();
|
||||
debugger;
|
||||
added.selectComparisonFunc();
|
||||
expect(second).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not modify the original filter chain', function() {
|
||||
var orig = new jasmineUnderTest.ExpectationFilterChain({}),
|
||||
f = jasmine.createSpy('f');
|
||||
|
||||
|
||||
orig.addFilter({selectComparisonFunc: f});
|
||||
|
||||
orig.selectComparisonFunc();
|
||||
expect(f).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectComparisonFunc', function() {
|
||||
describe('When no filters have #selectComparisonFunc', function() {
|
||||
it('returns undefined', function() {
|
||||
@@ -10,14 +38,14 @@ describe('ExpectationFilterChainSpec', function() {
|
||||
|
||||
describe('When some filters have #selectComparisonFunc', function() {
|
||||
it('calls the first filter that has #selectComparisonFunc', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain(),
|
||||
first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({selectComparisonFunc: first})
|
||||
.addFilter({selectComparisonFunc: second}),
|
||||
matcher = {},
|
||||
result;
|
||||
|
||||
chain.addFilter({selectComparisonFunc: first});
|
||||
chain.addFilter({selectComparisonFunc: second});
|
||||
result = chain.selectComparisonFunc(matcher);
|
||||
|
||||
expect(first).toHaveBeenCalledWith(matcher);
|
||||
@@ -38,17 +66,17 @@ describe('ExpectationFilterChainSpec', function() {
|
||||
|
||||
describe('When some filters have #buildFailureMessage', function() {
|
||||
it('calls the first filter that has #buildFailureMessage', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain(),
|
||||
first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({buildFailureMessage: first})
|
||||
.addFilter({buildFailureMessage: second}),
|
||||
matcherResult = {pass: false},
|
||||
matcherName = 'foo',
|
||||
args = [],
|
||||
util = {},
|
||||
result;
|
||||
|
||||
chain.addFilter({buildFailureMessage: first});
|
||||
chain.addFilter({buildFailureMessage: second});
|
||||
result = chain.buildFailureMessage(matcherResult, matcherName, args, util);
|
||||
|
||||
expect(first).toHaveBeenCalledWith(matcherResult, matcherName, args, util);
|
||||
@@ -60,19 +88,20 @@ describe('ExpectationFilterChainSpec', function() {
|
||||
|
||||
describe('#modifyFailureMessage', function() {
|
||||
it('calls each filter with the return value of the next previously added filter', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain(),
|
||||
first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
||||
third = jasmine.createSpy('third').and.returnValue('third'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({modifyFailureMessage: first})
|
||||
.addFilter({})
|
||||
.addFilter({modifyFailureMessage: third}),
|
||||
result;
|
||||
|
||||
chain.addFilter({modifyFailureMessage: first});
|
||||
chain.addFilter({})
|
||||
chain.addFilter({modifyFailureMessage: third});
|
||||
debugger;
|
||||
result = chain.modifyFailureMessage('original');
|
||||
|
||||
expect(third).toHaveBeenCalledWith('original');
|
||||
expect(first).toHaveBeenCalledWith('third');
|
||||
expect(result).toEqual('first');
|
||||
expect(first).toHaveBeenCalledWith('original');
|
||||
expect(third).toHaveBeenCalledWith('first');
|
||||
expect(result).toEqual('third');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user