Update test specs to use Jasmine 3 (#2089)
* Updated Karma and Jasmine versions * Added DOMObserver class. Supports promise-based testing of DOM changes Update asynchronous test specs to use promises or done() instead of waitsFor/runs * Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons * Global find + replace to fix syntax issues * Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality * Addressed review comments * Resolved merge conflicts with master * Fixed style errors * Use spy.calls.count() instead of manually tracking
This commit is contained in:
committed by
Pete Richards
parent
013eba744d
commit
433dee0314
@@ -28,14 +28,9 @@ define(
|
||||
var mockProviders,
|
||||
mockQ,
|
||||
resolves,
|
||||
mockCallback,
|
||||
testUsers,
|
||||
aggregator;
|
||||
|
||||
function callbackCalled() {
|
||||
return mockCallback.calls.length > 0;
|
||||
}
|
||||
|
||||
function resolveProviderPromises() {
|
||||
['a', 'b', 'c'].forEach(function (id, i) {
|
||||
resolves[id](testUsers[i]);
|
||||
@@ -57,7 +52,7 @@ define(
|
||||
['getUser']
|
||||
);
|
||||
|
||||
mockProvider.getUser.andReturn(new Promise(function (r) {
|
||||
mockProvider.getUser.and.returnValue(new Promise(function (r) {
|
||||
resolves[id] = r;
|
||||
}));
|
||||
|
||||
@@ -65,12 +60,10 @@ define(
|
||||
});
|
||||
|
||||
mockQ = jasmine.createSpyObj('$q', ['all']);
|
||||
mockQ.all.andCallFake(function (promises) {
|
||||
mockQ.all.and.callFake(function (promises) {
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
mockCallback = jasmine.createSpy('callback');
|
||||
|
||||
aggregator = new IdentityAggregator(
|
||||
mockQ,
|
||||
mockProviders
|
||||
@@ -91,47 +84,44 @@ define(
|
||||
});
|
||||
|
||||
it("returns the first result when it is defined", function () {
|
||||
aggregator.getUser().then(mockCallback);
|
||||
var promise = aggregator.getUser();
|
||||
|
||||
resolveProviderPromises();
|
||||
|
||||
waitsFor(callbackCalled);
|
||||
runs(function () {
|
||||
expect(mockCallback).toHaveBeenCalledWith(testUsers[0]);
|
||||
return promise.then(function (user) {
|
||||
expect(user).toEqual(testUsers[0]);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a later result when earlier results are undefined", function () {
|
||||
testUsers[0] = undefined;
|
||||
|
||||
aggregator.getUser().then(mockCallback);
|
||||
var promise = aggregator.getUser();
|
||||
|
||||
resolveProviderPromises();
|
||||
|
||||
waitsFor(callbackCalled);
|
||||
runs(function () {
|
||||
expect(mockCallback).toHaveBeenCalledWith(testUsers[1]);
|
||||
return promise.then(function (user) {
|
||||
expect(user).toEqual(testUsers[1]);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when no providers expose users", function () {
|
||||
testUsers = [undefined, undefined, undefined];
|
||||
|
||||
aggregator.getUser().then(mockCallback);
|
||||
var promise = aggregator.getUser();
|
||||
|
||||
resolveProviderPromises();
|
||||
|
||||
waitsFor(callbackCalled);
|
||||
runs(function () {
|
||||
expect(mockCallback).toHaveBeenCalledWith(undefined);
|
||||
return promise.then(function (user) {
|
||||
expect(user).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when there are no providers", function () {
|
||||
new IdentityAggregator(mockQ, []).getUser().then(mockCallback);
|
||||
waitsFor(callbackCalled);
|
||||
runs(function () {
|
||||
expect(mockCallback).toHaveBeenCalledWith(undefined);
|
||||
var promise = new IdentityAggregator(mockQ, []).getUser();
|
||||
|
||||
return promise.then(function (user) {
|
||||
expect(user).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user