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

@@ -37,10 +37,10 @@ define(
'remove'
]
);
mockInput.on.andCallFake(function (event, changeHandler) {
mockInput.on.and.callFake(function (event, changeHandler) {
changeHandler.apply(mockInput);
});
spyOn(fileInputService, "newInput").andReturn(
spyOn(fileInputService, "newInput").and.returnValue(
mockInput
);

View File

@@ -48,7 +48,7 @@ define(
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
mockLinker = jasmine.createSpyObj("templateLinker", ["link"]);
mockChangeTemplate = jasmine.createSpy('changeTemplate');
mockLinker.link.andReturn(mockChangeTemplate);
mockLinker.link.and.returnValue(mockChangeTemplate);
mctControl = new MCTControl(mockLinker, testControls);
});
@@ -73,7 +73,7 @@ define(
.not.toHaveBeenCalledWith(testControls[1]);
mockScope.key = "xyz";
mockScope.$watch.mostRecentCall.args[1]("xyz");
mockScope.$watch.calls.mostRecent().args[1]("xyz");
// Should have communicated the template path to
// ng-include via the "inclusion" field in scope

View File

@@ -49,27 +49,19 @@ define(
mockScope.field = "file-input";
mockScope.ngModel = {"file-input" : undefined};
element.on.andCallFake(function (event, clickHandler) {
element.on.and.callFake(function (event, clickHandler) {
clickHandler();
});
mockFileInputService.getInput.andReturn(
mockFileInputService.getInput.and.returnValue(
Promise.resolve({name: "file-name", body: "file-body"})
);
mctFileInput = new MCTFileInput(mockFileInputService);
// Need to wait for mock promise
var init = false;
runs(function () {
return new Promise(function (resolve) {
mctFileInput.link(mockScope, element, attrs, control);
setTimeout(function () {
init = true;
}, 100);
setTimeout(resolve, 100);
});
waitsFor(function () {
return init;
}, "File selection should have beeen simulated");
});
it("is restricted to attributes", function () {
@@ -85,11 +77,13 @@ define(
});
it("validates control on file selection", function () {
expect(control.$setValidity.callCount).toBe(2);
expect(control.$setValidity.argsForCall[0]).toEqual(
var calls = control.$setValidity.calls;
expect(calls.count()).toBe(2);
expect(calls.all()[0].args).toEqual(
['file-input', false]
);
expect(control.$setValidity.argsForCall[1]).toEqual(
expect(calls.all()[1].args).toEqual(
['file-input', true]
);
});

View File

@@ -61,7 +61,7 @@ define(
installController();
mockScope.$watch.mostRecentCall.args[1](someState);
mockScope.$watch.calls.mostRecent().args[1](someState);
expect(mockScope.$parent.someName).toBe(someState);
});

View File

@@ -50,7 +50,7 @@ define(
mockScope.datetime.min = 55;
mockScope.datetime.sec = 13;
mockScope.$watch.mostRecentCall.args[1]();
mockScope.$watch.calls.mostRecent().args[1]();
expect(mockScope.ngModel.test).toEqual(1417215313000);
});
@@ -66,7 +66,7 @@ define(
mockScope.datetime.min = 55;
// mockScope.datetime.sec = 13;
mockScope.$watch.mostRecentCall.args[1]();
mockScope.$watch.calls.mostRecent().args[1]();
expect(mockScope.partiallyComplete).toBeTruthy();
});
@@ -74,10 +74,10 @@ define(
it("reports 'undefined' for empty input", function () {
mockScope.ngModel = { test: 12345 };
mockScope.field = "test";
mockScope.$watch.mostRecentCall.args[1]();
mockScope.$watch.calls.mostRecent().args[1]();
// Clear all inputs
mockScope.datetime = {};
mockScope.$watch.mostRecentCall.args[1]();
mockScope.$watch.calls.mostRecent().args[1]();
// Should have cleared out the time stamp
expect(mockScope.ngModel.test).toBeUndefined();
@@ -91,7 +91,7 @@ define(
it("initializes form fields with values from ng-model", function () {
mockScope.ngModel = { test: 1417215313000 };
mockScope.field = "test";
mockScope.$watch.calls.forEach(function (call) {
mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === 'ngModel[field]') {
call.args[1](mockScope.ngModel.test);
}

View File

@@ -60,7 +60,7 @@ define(
mockScope.ngModel = { testKey: "initial test value" };
mockScope.structure = testStructure;
mockDialogService.getUserInput.andReturn(mockPromise);
mockDialogService.getUserInput.and.returnValue(mockPromise);
controller = new DialogButtonController(
mockScope,
@@ -80,7 +80,7 @@ define(
jasmine.any(Function)
);
mockScope.$watch.mostRecentCall.args[1](testStructure);
mockScope.$watch.calls.mostRecent().args[1](testStructure);
buttonStructure = controller.getButtonStructure();
expect(buttonStructure.cssClass).toEqual(testStructure.cssClass);
@@ -90,7 +90,7 @@ define(
});
it("shows a dialog when clicked", function () {
mockScope.$watch.mostRecentCall.args[1](testStructure);
mockScope.$watch.calls.mostRecent().args[1](testStructure);
// Verify precondition - no dialog shown
expect(mockDialogService.getUserInput).not.toHaveBeenCalled();
// Click!
@@ -102,31 +102,31 @@ define(
it("stores user input to the model", function () {
var key, input = {};
// Show dialog, click...
mockScope.$watch.mostRecentCall.args[1](testStructure);
mockScope.$watch.calls.mostRecent().args[1](testStructure);
controller.getButtonStructure().click();
// Should be listening to 'then'
expect(mockPromise.then)
.toHaveBeenCalledWith(jasmine.any(Function));
// Find the key that the dialog should return
key = mockDialogService.getUserInput.mostRecentCall
key = mockDialogService.getUserInput.calls.mostRecent()
.args[0].sections[0].rows[0].key;
// Provide 'user input'
input[key] = "test user input";
// Resolve the promise with it
mockPromise.then.mostRecentCall.args[0](input);
mockPromise.then.calls.mostRecent().args[0](input);
// ... should have been placed into the model
expect(mockScope.ngModel.testKey).toEqual("test user input");
});
it("supplies initial model state to the dialog", function () {
var key, state;
mockScope.$watch.mostRecentCall.args[1](testStructure);
mockScope.$watch.calls.mostRecent().args[1](testStructure);
controller.getButtonStructure().click();
// Find the key that the dialog should return
key = mockDialogService.getUserInput.mostRecentCall
key = mockDialogService.getUserInput.calls.mostRecent()
.args[0].sections[0].rows[0].key;
// Get the initial state provided to the dialog
state = mockDialogService.getUserInput.mostRecentCall.args[1];
state = mockDialogService.getUserInput.calls.mostRecent().args[1];
// Should have had value from ngModel stored to that key
expect(state[key]).toEqual("initial test value");
});

View File

@@ -44,7 +44,7 @@ define(
it("conveys form status to parent scope", function () {
var someState = { someKey: "some value" };
mockScope.name = "someName";
mockScope.$watch.mostRecentCall.args[1](someState);
mockScope.$watch.calls.mostRecent().args[1](someState);
expect(mockScope.$parent.someName).toBe(someState);
});