Merge branch 'main' into 3.99
This commit is contained in:
@@ -4,7 +4,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.configure({random: false});
|
||||
env.configure({ random: false });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
@@ -17,7 +17,11 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.it('spec using custom async matcher', function() {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: function() { return Promise.resolve({ pass: true }); } };
|
||||
return {
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,8 +43,12 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() { return Promise.resolve({ pass: true }); },
|
||||
negativeCompare: function() { return Promise.resolve({ pass: true }); }
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
},
|
||||
negativeCompare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -74,26 +82,31 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
"Expected 'a' to be real."
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("passes the jasmine utility to the matcher factory", function (done) {
|
||||
it('passes the jasmine utility to the matcher factory', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcherFactory = function (util) {
|
||||
var matcherFactory = function(util) {
|
||||
return {
|
||||
compare: function () {
|
||||
return Promise.resolve({pass: true});
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy", matcherFactory);
|
||||
matcherFactorySpy = jasmine.createSpy(
|
||||
'matcherFactorySpy',
|
||||
matcherFactory
|
||||
);
|
||||
|
||||
env.it("spec with expectation", function () {
|
||||
env.it('spec with expectation', function() {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: matcherFactorySpy
|
||||
});
|
||||
@@ -101,7 +114,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
return env.expectAsync(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function () {
|
||||
var specExpectations = function() {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||
);
|
||||
@@ -113,22 +126,25 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
|
||||
// TODO: remove this in the next major release.
|
||||
describe('When a matcher factory takes at least two arguments', function() {
|
||||
it("passes the jasmine utility and current equality testers to the matcher factory", function (done) {
|
||||
it('passes the jasmine utility and current equality testers to the matcher factory', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcherFactory = function (util, customTesters) {
|
||||
var matcherFactory = function(util, customTesters) {
|
||||
return {
|
||||
compare: function () {
|
||||
return Promise.resolve({pass: true});
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy", matcherFactory),
|
||||
customEqualityFn = function () {
|
||||
matcherFactorySpy = jasmine.createSpy(
|
||||
'matcherFactorySpy',
|
||||
matcherFactory
|
||||
),
|
||||
customEqualityFn = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
env.it("spec with expectation", function () {
|
||||
env.it('spec with expectation', function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: matcherFactorySpy
|
||||
@@ -137,7 +153,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
return env.expectAsync(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function () {
|
||||
var specExpectations = function() {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||
[customEqualityFn]
|
||||
@@ -145,36 +161,40 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
};
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it("provides custom equality testers to the matcher factory via matchersUtil", function(done) {
|
||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcherFactory = function (matchersUtil) {
|
||||
var matcherFactory = function(matchersUtil) {
|
||||
return {
|
||||
compare: function (actual, expected) {
|
||||
return Promise.resolve({pass: matchersUtil.equals(actual[0], expected)});
|
||||
compare: function(actual, expected) {
|
||||
return Promise.resolve({
|
||||
pass: matchersUtil.equals(actual[0], expected)
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
customEqualityFn = jasmine.createSpy("customEqualityFn").and.callFake(function (a, b) {
|
||||
return a.toString() === b;
|
||||
});
|
||||
customEqualityFn = jasmine
|
||||
.createSpy('customEqualityFn')
|
||||
.and.callFake(function(a, b) {
|
||||
return a.toString() === b;
|
||||
});
|
||||
|
||||
env.it("spec with expectation", function() {
|
||||
env.it('spec with expectation', function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addAsyncMatchers({
|
||||
toBeArrayWithFirstElement: matcherFactory
|
||||
});
|
||||
|
||||
return env.expectAsync([1, 2]).toBeArrayWithFirstElement("1");
|
||||
return env.expectAsync([1, 2]).toBeArrayWithFirstElement('1');
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(customEqualityFn).toHaveBeenCalledWith(1, "1");
|
||||
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||
expect(result.failedExpectations).toEqual([]);
|
||||
};
|
||||
|
||||
@@ -182,37 +202,41 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function (done) {
|
||||
var matcherFactory = function (matchersUtil, customEqualityTesters) {
|
||||
return { compare: function () {} };
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
|
||||
var matcherFactory = function(matchersUtil, customEqualityTesters) {
|
||||
return { compare: function() {} };
|
||||
};
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.beforeEach(function() {
|
||||
env.addAsyncMatchers({toBeFoo: matcherFactory});
|
||||
env.addAsyncMatchers({toBeBar: matcherFactory});
|
||||
env.addAsyncMatchers({ toBeFoo: matcherFactory });
|
||||
env.addAsyncMatchers({ toBeBar: matcherFactory });
|
||||
});
|
||||
|
||||
env.it('a spec', function() {});
|
||||
env.it('another spec', function() {});
|
||||
|
||||
function jasmineDone() {
|
||||
expect(env.deprecated).toHaveBeenCalledWith(jasmine.stringMatching(
|
||||
'The matcher factory for "toBeFoo" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
));
|
||||
expect(env.deprecated).toHaveBeenCalledWith(jasmine.stringMatching(
|
||||
'The matcher factory for "toBeBar" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
));
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeFoo" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeBar" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({jasmineDone: jasmineDone});
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user