Skip to content

Commit

Permalink
Merge branch 'expect-context'
Browse files Browse the repository at this point in the history
- Fixes #641
  • Loading branch information
Gregg Van Hove committed Oct 24, 2018
2 parents e6a60a7 + 2d303a6 commit 1b5e0c0
Show file tree
Hide file tree
Showing 19 changed files with 1,475 additions and 885 deletions.
675 changes: 409 additions & 266 deletions lib/jasmine-core/jasmine.js

Large diffs are not rendered by default.

421 changes: 116 additions & 305 deletions spec/core/AsyncExpectationSpec.js

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions spec/core/ExpectationFilterChainSpec.js
@@ -0,0 +1,113 @@
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();
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() {
var chain = new jasmineUnderTest.ExpectationFilterChain();
chain.addFilter({});
expect(chain.selectComparisonFunc()).toBeUndefined();
});
});

describe('When some filters have #selectComparisonFunc', function() {
it('calls the first filter that has #selectComparisonFunc', function() {
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;

result = chain.selectComparisonFunc(matcher);

expect(first).toHaveBeenCalledWith(matcher);
expect(second).not.toHaveBeenCalled();
expect(result).toEqual('first');
});
});
});

describe('#buildFailureMessage', function() {
describe('When no filters have #buildFailureMessage', function() {
it('returns undefined', function() {
var chain = new jasmineUnderTest.ExpectationFilterChain();
chain.addFilter({});
expect(chain.buildFailureMessage()).toBeUndefined();
});
});

describe('When some filters have #buildFailureMessage', function() {
it('calls the first filter that has #buildFailureMessage', function() {
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;

result = chain.buildFailureMessage(matcherResult, matcherName, args, util);

expect(first).toHaveBeenCalledWith(matcherResult, matcherName, args, util);
expect(second).not.toHaveBeenCalled();
expect(result).toEqual('first');
});
});
});

describe('#modifyFailureMessage', 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'),
second = jasmine.createSpy('second').and.returnValue('second'),
chain = new jasmineUnderTest.ExpectationFilterChain()
.addFilter({modifyFailureMessage: first})
.addFilter({modifyFailureMessage: second}),
result;

result = chain.modifyFailureMessage('original');

expect(first).toHaveBeenCalledWith('original');
expect(second).not.toHaveBeenCalled();
expect(result).toEqual('first');
});
});
});
});

0 comments on commit 1b5e0c0

Please sign in to comment.