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

@@ -38,7 +38,7 @@ define(
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"])
];
mockedSaveActions.forEach(function (action) {
action.getMetadata.andReturn(mockSaveActionMetadata);
action.getMetadata.and.returnValue(mockSaveActionMetadata);
});
return mockedSaveActions;
} else if (actionContext.category === "conclude-editing") {
@@ -54,14 +54,14 @@ define(
beforeEach(function () {
mockActions = jasmine.createSpyObj("action", ["getActions"]);
mockActions.getActions.andCallFake(fakeGetActions);
mockActions.getActions.and.callFake(fakeGetActions);
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
mockScope.action = mockActions;
controller = new EditActionController(mockScope);
});
function makeControllerUpdateActions() {
mockScope.$watch.mostRecentCall.args[1]();
mockScope.$watch.calls.mostRecent().args[1]();
}
it("watches scope that may change applicable actions", function () {

View File

@@ -61,17 +61,17 @@ define(
mockLocation = jasmine.createSpyObj('$location',
["search"]
);
mockLocation.search.andReturn({"view": "fixed"});
mockLocation.search.and.returnValue({"view": "fixed"});
mockNavigationService = jasmine.createSpyObj('navigationService',
["checkBeforeNavigation"]
);
removeCheck = jasmine.createSpy('removeCheck');
mockNavigationService.checkBeforeNavigation.andReturn(removeCheck);
mockNavigationService.checkBeforeNavigation.and.returnValue(removeCheck);
mockObject.getId.andReturn("test");
mockObject.getModel.andReturn({ name: "Test object" });
mockObject.getCapability.andCallFake(function (key) {
mockObject.getId.and.returnValue("test");
mockObject.getModel.and.returnValue({ name: "Test object" });
mockObject.getCapability.and.callFake(function (key) {
return mockCapabilities[key];
});
@@ -81,10 +81,10 @@ define(
{ key: 'xyz' }
];
mockObject.useCapability.andCallFake(function (c) {
mockObject.useCapability.and.callFake(function (c) {
return (c === 'view') && testViews;
});
mockLocation.search.andReturn({ view: 'def' });
mockLocation.search.and.returnValue({ view: 'def' });
mockScope.domainObject = mockObject;
@@ -99,17 +99,17 @@ define(
expect(mockNavigationService.checkBeforeNavigation)
.toHaveBeenCalledWith(jasmine.any(Function));
var checkFn = mockNavigationService.checkBeforeNavigation.mostRecentCall.args[0];
var checkFn = mockNavigationService.checkBeforeNavigation.calls.mostRecent().args[0];
mockEditorCapability.isEditContextRoot.andReturn(false);
mockEditorCapability.dirty.andReturn(false);
mockEditorCapability.isEditContextRoot.and.returnValue(false);
mockEditorCapability.dirty.and.returnValue(false);
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
mockEditorCapability.isEditContextRoot.andReturn(true);
mockEditorCapability.isEditContextRoot.and.returnValue(true);
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
mockEditorCapability.dirty.andReturn(true);
mockEditorCapability.dirty.and.returnValue(true);
expect(checkFn())
.toBe("Continuing will cause the loss of any unsaved changes.");
@@ -119,7 +119,7 @@ define(
expect(mockScope.$on)
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
expect(mockEditorCapability.finish).toHaveBeenCalled();
expect(removeCheck).toHaveBeenCalled();

View File

@@ -41,13 +41,13 @@ define(
['getTrueRoot']
);
mockDomainObject.getId.andReturn('test-id');
mockDomainObject.getCapability.andReturn(mockContext);
mockDomainObject.getId.and.returnValue('test-id');
mockDomainObject.getCapability.and.returnValue(mockContext);
// Return a new instance of the root object each time
mockContext.getTrueRoot.andCallFake(function () {
mockContext.getTrueRoot.and.callFake(function () {
var mockRoot = jasmine.createSpyObj('root', ['getId']);
mockRoot.getId.andReturn('root-id');
mockRoot.getId.and.returnValue('root-id');
return mockRoot;
});
@@ -63,7 +63,7 @@ define(
});
it("exposes the root object found via the object's context capability", function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Verify that the correct capability was used
expect(mockDomainObject.getCapability)
@@ -76,10 +76,10 @@ define(
it("preserves the same root instance to avoid excessive refreshing", function () {
var firstRoot;
// Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot();
// Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting
expect(controller.getRoot()).toBe(firstRoot);
@@ -90,18 +90,18 @@ define(
it("updates the root when it changes", function () {
var firstRoot;
// Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot();
// Change the exposed root
mockContext.getTrueRoot.andCallFake(function () {
mockContext.getTrueRoot.and.callFake(function () {
var mockRoot = jasmine.createSpyObj('root', ['getId']);
mockRoot.getId.andReturn('other-root-id');
mockRoot.getId.and.returnValue('other-root-id');
return mockRoot;
});
// Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting

View File

@@ -63,13 +63,13 @@ define(
mockMutationCapability = jasmine.createSpyObj("mutationCapability", [
"listen"
]);
mockMutationCapability.listen.andReturn(mockUnlisten);
mockMutationCapability.listen.and.returnValue(mockUnlisten);
mockDomainObject = jasmine.createSpyObj("domainObject", [
"getCapability",
"useCapability"
]);
mockDomainObject.useCapability.andReturn(mockCompositionCapability);
mockDomainObject.getCapability.andReturn(mockMutationCapability);
mockDomainObject.useCapability.and.returnValue(mockCompositionCapability);
mockDomainObject.getCapability.and.returnValue(mockMutationCapability);
mockScope = jasmine.createSpyObj("$scope", ['$on']);
mockSelection = jasmine.createSpyObj("selection", [
@@ -77,7 +77,7 @@ define(
'off',
'get'
]);
mockSelection.get.andReturn([]);
mockSelection.get.and.returnValue([]);
mockOpenMCT = {
selection: mockSelection
};
@@ -88,7 +88,7 @@ define(
}
};
spyOn(ElementsController.prototype, 'refreshComposition').andCallThrough();
spyOn(ElementsController.prototype, 'refreshComposition').and.callThrough();
controller = new ElementsController(mockScope, mockOpenMCT);
});
@@ -123,29 +123,29 @@ define(
});
it("refreshes composition on selection", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(ElementsController.prototype.refreshComposition).toHaveBeenCalledWith(mockDomainObject);
});
it("listens on mutation and refreshes composition", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockDomainObject.getCapability).toHaveBeenCalledWith('mutation');
expect(mockMutationCapability.listen).toHaveBeenCalled();
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(1);
expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(1);
mockMutationCapability.listen.mostRecentCall.args[0](mockDomainObject);
mockMutationCapability.listen.calls.mostRecent().args[0](mockDomainObject);
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(2);
expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(2);
});
it("cleans up mutation listener when selection changes", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockMutationCapability.listen).toHaveBeenCalled();
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockUnlisten).toHaveBeenCalled();
});
@@ -156,7 +156,7 @@ define(
elementProxy: {}
}
};
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation');
});
@@ -167,13 +167,13 @@ define(
firstCompositionCallback,
secondCompositionCallback;
spyOn(mockCompositionCapability, "then").andCallThrough();
spyOn(mockCompositionCapability, "then").and.callThrough();
controller.refreshComposition(mockDomainObject);
controller.refreshComposition(mockDomainObject);
firstCompositionCallback = mockCompositionCapability.then.calls[0].args[0];
secondCompositionCallback = mockCompositionCapability.then.calls[1].args[0];
firstCompositionCallback = mockCompositionCapability.then.calls.all()[0].args[0];
secondCompositionCallback = mockCompositionCapability.then.calls.all()[1].args[0];
secondCompositionCallback(secondMockCompositionObjects);
firstCompositionCallback(mockCompositionObjects);