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

@@ -65,28 +65,28 @@ define(
mockElements = {};
mockContents = {};
mockTemplateRequest.andReturn(mockPromise);
mockCompile.andCallFake(function (toCompile) {
mockTemplateRequest.and.returnValue(mockPromise);
mockCompile.and.callFake(function (toCompile) {
var html = typeof toCompile === 'string' ?
toCompile : toCompile.testHtml;
mockTemplates[html] = jasmine.createSpy('template');
mockElements[html] =
jasmine.createSpyObj('templateEl', JQLITE_METHODS);
mockTemplates[html].andReturn(mockElements[html]);
mockTemplates[html].and.returnValue(mockElements[html]);
return mockTemplates[html];
});
mockSce.trustAsResourceUrl.andCallFake(function (url) {
mockSce.trustAsResourceUrl.and.callFake(function (url) {
return { trusted: url };
});
mockScope.$new.andReturn(mockNewScope);
mockElement.html.andCallFake(function (html) {
mockScope.$new.and.returnValue(mockNewScope);
mockElement.html.and.callFake(function (html) {
mockContents[html] =
jasmine.createSpyObj('contentsEl', JQLITE_METHODS);
mockContents[html].testHtml = html;
});
mockElement.contents.andCallFake(function () {
mockElement.contents.and.callFake(function () {
return mockContents[
mockElement.html.mostRecentCall.args[0]
mockElement.html.calls.mostRecent().args[0]
];
});
@@ -108,7 +108,7 @@ define(
commentElement;
function findCommentElement() {
mockCompile.calls.forEach(function (call) {
mockCompile.calls.all().forEach(function (call) {
var html = call.args[0];
if (html.indexOf("<!--") > -1) {
commentElement = mockElements[html];
@@ -144,7 +144,7 @@ define(
testUrl = linker.getPath(testExt);
testTemplate = "<div>Some template!</div>";
changeTemplate(testExt);
mockPromise.then.mostRecentCall
mockPromise.then.calls.mostRecent()
.args[0](testTemplate);
});
@@ -172,12 +172,12 @@ define(
});
it("clears templates when called with undefined", function () {
expect(mockElement.replaceWith.callCount)
expect(mockElement.replaceWith.calls.count())
.toEqual(1);
changeTemplate(undefined);
expect(mockElement.replaceWith.callCount)
expect(mockElement.replaceWith.calls.count())
.toEqual(2);
expect(mockElement.replaceWith.mostRecentCall.args[0])
expect(mockElement.replaceWith.calls.mostRecent().args[0])
.toEqual(commentElement);
});
@@ -191,14 +191,14 @@ define(
testExtension("some", "bad", "template.html")
);
// Reject the template promise
mockPromise.then.mostRecentCall.args[1]();
mockPromise.then.calls.mostRecent().args[1]();
});
it("removes the element from the DOM", function () {
expect(mockElement.replaceWith.callCount)
expect(mockElement.replaceWith.calls.count())
.toEqual(2);
expect(
mockElement.replaceWith.mostRecentCall.args[0]
mockElement.replaceWith.calls.mostRecent().args[0]
).toEqual(commentElement);
});