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

@@ -32,15 +32,9 @@ define(
mockCreationService,
mockParent,
mockCreatedObject,
mockCallback,
decorator;
function calledBack() {
return mockCallback.calls.length > 0;
}
beforeEach(function () {
mockCallback = jasmine.createSpy('callback');
mockIdentityService = jasmine.createSpyObj(
'identityService',
['getUser']
@@ -58,10 +52,10 @@ define(
['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability']
);
mockCreationService.createObject
.andReturn(Promise.resolve(mockCreatedObject));
.and.returnValue(Promise.resolve(mockCreatedObject));
mockIdentityService.getUser
.andReturn(Promise.resolve({ key: "test-user-id" }));
mockParent.getId.andReturn('test-id');
.and.returnValue(Promise.resolve({ key: "test-user-id" }));
mockParent.getId.and.returnValue('test-id');
decorator = new IdentityCreationDecorator(
mockIdentityService,
mockCreationService
@@ -71,33 +65,27 @@ define(
it("delegates to its decorated service when identity is available", function () {
var testModel = { someKey: "some value" };
decorator.createObject(testModel, mockParent)
.then(mockCallback);
waitsFor(calledBack);
runs(function () {
expect(mockCallback)
.toHaveBeenCalledWith(mockCreatedObject);
});
return decorator.createObject(testModel, mockParent)
.then(function (object) {
expect(object).toEqual(mockCreatedObject);
});
});
it("adds a creator property", function () {
var testModel = { someKey: "some value" };
decorator.createObject(testModel, mockParent)
.then(mockCallback);
return decorator.createObject(testModel, mockParent)
.then(function (object) {
expect(object)
.toEqual(mockCreatedObject);
waitsFor(calledBack);
runs(function () {
expect(mockCallback)
.toHaveBeenCalledWith(mockCreatedObject);
// Make sure arguments were delegated appropriately
expect(mockCreationService.createObject)
// Make sure arguments were delegated appropriately
expect(mockCreationService.createObject)
.toHaveBeenCalledWith(
{ someKey: "some value", creator: "test-user-id" },
mockParent
);
});
});
});
});