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:
Andrew Henry
2018-06-29 17:32:59 -07:00
committed by Pete Richards
parent 013eba744d
commit 433dee0314
305 changed files with 2866 additions and 3324 deletions

View File

@@ -67,7 +67,7 @@ define(
a: { someKey: "some value" },
b: { someOtherKey: "some other value" }
};
mockModelService.getModels.andReturn(asPromise(testModels));
mockModelService.getModels.and.returnValue(asPromise(testModels));
decorator = new CachingModelDecorator(
new ModelCacheService(),
mockModelService
@@ -80,19 +80,19 @@ define(
});
it("does not try to reload cached models", function () {
mockModelService.getModels.andReturn(asPromise({ a: testModels.a }));
mockModelService.getModels.and.returnValue(asPromise({ a: testModels.a }));
decorator.getModels(['a']);
mockModelService.getModels.andReturn(asPromise(testModels));
mockModelService.getModels.and.returnValue(asPromise(testModels));
decorator.getModels(['a', 'b']);
expect(mockModelService.getModels).not.toHaveBeenCalledWith(['a', 'b']);
expect(mockModelService.getModels.mostRecentCall.args[0]).toEqual(['b']);
expect(mockModelService.getModels.calls.mostRecent().args[0]).toEqual(['b']);
});
it("does not call its wrapped model service if not needed", function () {
decorator.getModels(['a', 'b']);
expect(mockModelService.getModels.calls.length).toEqual(1);
expect(mockModelService.getModels.calls.count()).toEqual(1);
decorator.getModels(['a', 'b']).then(mockCallback);
expect(mockModelService.getModels.calls.length).toEqual(1);
expect(mockModelService.getModels.calls.count()).toEqual(1);
// Verify that we still got back our models, even though
// no new call to the wrapped service was made
expect(mockCallback).toHaveBeenCalledWith(testModels);
@@ -105,9 +105,9 @@ define(
promiseB = fakePromise();
// Issue two calls before those promises resolve
mockModelService.getModels.andReturn(promiseA);
mockModelService.getModels.and.returnValue(promiseA);
decorator.getModels(['a']);
mockModelService.getModels.andReturn(promiseB);
mockModelService.getModels.and.returnValue(promiseB);
decorator.getModels(['a']).then(mockCallback);
// Then resolve those promises. Note that we're whiteboxing here
@@ -119,9 +119,9 @@ define(
});
// Ensure that we have a pointer-identical instance
expect(mockCallback.mostRecentCall.args[0].a)
expect(mockCallback.calls.mostRecent().args[0].a)
.toEqual({ someNewKey: "some other value" });
expect(mockCallback.mostRecentCall.args[0].a)
expect(mockCallback.calls.mostRecent().args[0].a)
.toBe(testModels.a);
});
@@ -132,9 +132,9 @@ define(
promiseB = fakePromise();
// Issue two calls before those promises resolve
mockModelService.getModels.andReturn(promiseA);
mockModelService.getModels.and.returnValue(promiseA);
decorator.getModels(['a']);
mockModelService.getModels.andReturn(promiseB);
mockModelService.getModels.and.returnValue(promiseB);
decorator.getModels(['a']).then(mockCallback);
// Some model providers might erroneously add undefined values
@@ -147,7 +147,7 @@ define(
});
// Should still have gotten the model
expect(mockCallback.mostRecentCall.args[0].a)
expect(mockCallback.calls.mostRecent().args[0].a)
.toEqual({ someNewKey: "some other value" });
});

View File

@@ -47,7 +47,7 @@ define(
testId: { someKey: "some value" }
};
mockModelService.getModels.andReturn(asPromise(testModels));
mockModelService.getModels.and.returnValue(asPromise(testModels));
decorator = new MissingModelDecorator(mockModelService);
});

View File

@@ -43,11 +43,11 @@ define(
"mockProvider" + i,
["getModels"]
);
mockProvider.getModels.andReturn(models);
mockProvider.getModels.and.returnValue(models);
return mockProvider;
});
mockQ.all.andReturn({
mockQ.all.and.returnValue({
then: function (c) {
return c(modelList);
}

View File

@@ -67,7 +67,7 @@ define(
mockNow = jasmine.createSpy("now");
mockPersistenceService.readObject
.andCallFake(function (space, id) {
.and.callFake(function (space, id) {
return mockPromise({
space: space,
id: id,
@@ -76,7 +76,7 @@ define(
});
});
mockPersistenceService.listSpaces
.andReturn(mockPromise([SPACE]));
.and.returnValue(mockPromise([SPACE]));
provider = new PersistedModelProvider(
mockPersistenceService,
@@ -94,9 +94,9 @@ define(
});
expect(models).toEqual({
a: { space: SPACE, id: "a", persisted: 0 },
x: { space: SPACE, id: "x", persisted: 0 },
zz: { space: SPACE, id: "zz", persisted: 0 }
a: { space: SPACE, id: "a", persisted: 0, modified: undefined },
x: { space: SPACE, id: "x", persisted: 0, modified: undefined },
zz: { space: SPACE, id: "zz", persisted: 0, modified: undefined }
});
});
@@ -110,12 +110,12 @@ define(
d: { name: "D" }
};
mockPersistenceService.readObject.andCallFake(
mockPersistenceService.readObject.and.callFake(
function (space, id) {
return mockPromise(testModels[id]);
}
);
mockNow.andReturn(12321);
mockNow.and.returnValue(12321);
provider.getModels(Object.keys(testModels)).then(mockCallback);

View File

@@ -58,17 +58,17 @@ define(
var mockPromise = { then: function () {
return;
} };
mockQ.when.andReturn(mockPromise);
mockQ.when.and.returnValue(mockPromise);
// Verify that we got the promise as the return value
expect(provider.getModels(["a", "b"])).toEqual(mockPromise);
// Verify that the promise has the desired models
expect(mockQ.when.callCount).toEqual(1);
expect(mockQ.when.mostRecentCall.args[0].a.name).toEqual("Thing A");
expect(mockQ.when.mostRecentCall.args[0].a.someProperty).toEqual("Some Value A");
expect(mockQ.when.mostRecentCall.args[0].b.name).toEqual("Thing B");
expect(mockQ.when.mostRecentCall.args[0].b.someProperty).toEqual("Some Value B");
expect(mockQ.when.calls.count()).toEqual(1);
expect(mockQ.when.calls.mostRecent().args[0].a.name).toEqual("Thing A");
expect(mockQ.when.calls.mostRecent().args[0].a.someProperty).toEqual("Some Value A");
expect(mockQ.when.calls.mostRecent().args[0].b.name).toEqual("Thing B");
expect(mockQ.when.calls.mostRecent().args[0].b.someProperty).toEqual("Some Value B");
});
@@ -76,8 +76,8 @@ define(
provider.getModels(["c"]);
// Verify that the promise has the desired models
expect(mockQ.when.callCount).toEqual(1);
expect(mockQ.when.mostRecentCall.args[0].c).toBeUndefined();
expect(mockQ.when.calls.count()).toEqual(1);
expect(mockQ.when.calls.mostRecent().args[0].c).toBeUndefined();
});
it("logs a warning when model definitions are malformed", function () {
@@ -94,7 +94,7 @@ define(
], mockQ, mockLog)).toBeDefined();
// Should show warnings
expect(mockLog.warn.callCount).toEqual(5);
expect(mockLog.warn.calls.count()).toEqual(5);
});
});