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

@ -47,7 +47,7 @@ define(
mockFormat;
function getCallback(target, event) {
return target.calls.filter(function (call) {
return target.calls.all().filter(function (call) {
return call.args[0] === event;
})[0].args[1];
}
@ -61,7 +61,7 @@ define(
'$watchCollection',
'$digest'
]);
mockScope.$watchCollection.andCallFake(function (event, callback) {
mockScope.$watchCollection.and.callFake(function (event, callback) {
watches[event] = callback;
});
@ -80,7 +80,7 @@ define(
mockScope.displayHeaders = true;
mockWindow = jasmine.createSpyObj('$window', ['requestAnimationFrame']);
mockWindow.requestAnimationFrame.andCallFake(function (f) {
mockWindow.requestAnimationFrame.and.callFake(function (f) {
return f();
});
@ -91,7 +91,7 @@ define(
mockFormatService = jasmine.createSpyObj('formatService', [
'getFormat'
]);
mockFormatService.getFormat.andReturn(mockFormat);
mockFormatService.getFormat.and.returnValue(mockFormat);
controller = new MCTTableController(
mockScope,
@ -101,7 +101,7 @@ define(
mockFormatService,
{time: mockConductor}
);
spyOn(controller, 'setVisibleRows').andCallThrough();
spyOn(controller, 'setVisibleRows').and.callThrough();
});
it('Reacts to changes to filters, headers, and rows', function () {
@ -186,8 +186,8 @@ define(
mockScope.sortDirection = 'asc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@ -204,8 +204,8 @@ define(
mockScope.sortDirection = 'desc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@ -220,9 +220,9 @@ define(
mockScope.sortDirection = 'asc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockConductor.timeOfInterest.andReturn(toi);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
mockConductor.timeOfInterest.and.returnValue(toi);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@ -230,19 +230,10 @@ define(
//Mock setting the rows on scope
var rowsCallback = getCallback(mockScope.$watch, 'rows');
var setRowsPromise = rowsCallback(rowsAsc);
var promiseResolved = false;
setRowsPromise.then(function () {
promiseResolved = true;
});
waitsFor(function () {
return promiseResolved;
}, "promise to resolve", 100);
runs(function () {
return setRowsPromise.then(function () {
expect(mockScope.toiRowIndex).toBe(2);
});
});
});
@ -322,7 +313,7 @@ define(
mockScope.exportAsCSV();
expect(mockExportService.exportCSV)
.toHaveBeenCalled();
mockExportService.exportCSV.mostRecentCall.args[0]
mockExportService.exportCSV.calls.mostRecent().args[0]
.forEach(function (row, i) {
Object.keys(row).forEach(function (k) {
expect(row[k]).toEqual(
@ -389,18 +380,11 @@ define(
var oldRows;
mockScope.rows = testRows;
var setRowsPromise = controller.setRows(testRows);
var promiseResolved = false;
setRowsPromise.then(function () {
promiseResolved = true;
});
oldRows = mockScope.visibleRows;
mockScope.toggleSort('col2');
waitsFor(function () {
return promiseResolved;
}, "promise to resolve", 100);
runs(function () {
return setRowsPromise.then(function () {
expect(mockScope.visibleRows).not.toEqual(oldRows);
});
});