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:
committed by
Pete Richards
parent
013eba744d
commit
433dee0314
@@ -66,9 +66,9 @@ define(
|
||||
height: 75
|
||||
};
|
||||
mockElement[0] = mockPlainEl;
|
||||
mockPlainEl.getBoundingClientRect.andReturn(testRect);
|
||||
mockPlainEl.getBoundingClientRect.and.returnValue(testRect);
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
|
||||
mctClickElsewhere = new MCTClickElsewhere(mockDocument);
|
||||
mctClickElsewhere.link(mockScope, mockElement, testAttrs);
|
||||
@@ -80,14 +80,14 @@ define(
|
||||
|
||||
it("detaches listeners when destroyed", function () {
|
||||
expect(mockBody.off).not.toHaveBeenCalled();
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === '$destroy') {
|
||||
call.args[1]();
|
||||
}
|
||||
});
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
expect(mockBody.off.mostRecentCall.args)
|
||||
.toEqual(mockBody.on.mostRecentCall.args);
|
||||
expect(mockBody.off.calls.mostRecent().args)
|
||||
.toEqual(mockBody.on.calls.mostRecent().args);
|
||||
});
|
||||
|
||||
it("listens for mousedown on the document's body", function () {
|
||||
@@ -97,7 +97,7 @@ define(
|
||||
|
||||
describe("when a click occurs outside the element's bounds", function () {
|
||||
beforeEach(function () {
|
||||
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||
mockBody.on.calls.mostRecent().args[1](testEvent(
|
||||
testRect.left + testRect.width + 10,
|
||||
testRect.top + testRect.height + 10
|
||||
));
|
||||
@@ -105,7 +105,7 @@ define(
|
||||
|
||||
it("triggers an evaluation of its related Angular expression", function () {
|
||||
expect(mockScope.$apply).toHaveBeenCalled();
|
||||
mockScope.$apply.mostRecentCall.args[0]();
|
||||
mockScope.$apply.calls.mostRecent().args[0]();
|
||||
expect(mockScope.$eval)
|
||||
.toHaveBeenCalledWith(testAttrs.mctClickElsewhere);
|
||||
});
|
||||
@@ -113,7 +113,7 @@ define(
|
||||
|
||||
describe("when a click occurs within the element's bounds", function () {
|
||||
beforeEach(function () {
|
||||
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||
mockBody.on.calls.mostRecent().args[1](testEvent(
|
||||
testRect.left + testRect.width / 2,
|
||||
testRect.top + testRect.height / 2
|
||||
));
|
||||
|
||||
@@ -61,8 +61,8 @@ define(
|
||||
mctDragUp: "ending a drag"
|
||||
};
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockAgentService.isMobile.andReturn(true);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockAgentService.isMobile.and.returnValue(true);
|
||||
|
||||
mctDrag = new MCTDrag(mockDocument, mockAgentService);
|
||||
mctDrag.link(mockScope, mockElement, testAttrs);
|
||||
@@ -84,7 +84,7 @@ define(
|
||||
|
||||
it("invokes mctDragDown when dragging begins", function () {
|
||||
var event = testEvent(42, 60);
|
||||
mockElement.on.mostRecentCall.args[1](event);
|
||||
mockElement.on.calls.mostRecent().args[1](event);
|
||||
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||
testAttrs.mctDragDown,
|
||||
{ delta: [0, 0], $event: event }
|
||||
@@ -92,7 +92,7 @@ define(
|
||||
});
|
||||
|
||||
it("listens for touchmove after dragging begins", function () {
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
expect(mockBody.on).toHaveBeenCalledWith(
|
||||
"touchmove",
|
||||
jasmine.any(Function)
|
||||
@@ -106,10 +106,10 @@ define(
|
||||
it("invokes mctDrag expression during drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchmove') {
|
||||
call.args[1](event = testEvent(52, 200));
|
||||
}
|
||||
@@ -125,16 +125,16 @@ define(
|
||||
it("invokes mctDragUp expression after drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchmove') {
|
||||
call.args[1](testEvent(52, 200));
|
||||
}
|
||||
});
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchend') {
|
||||
call.args[1](event = testEvent(40, 71));
|
||||
}
|
||||
@@ -189,8 +189,8 @@ define(
|
||||
mctDragUp: "ending a drag"
|
||||
};
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockAgentService.isMobile.andReturn(false);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockAgentService.isMobile.and.returnValue(false);
|
||||
|
||||
mctDrag = new MCTDrag(mockDocument, mockAgentService);
|
||||
mctDrag.link(mockScope, mockElement, testAttrs);
|
||||
@@ -212,7 +212,7 @@ define(
|
||||
|
||||
it("invokes mctDragDown when dragging begins", function () {
|
||||
var event = testEvent(42, 60);
|
||||
mockElement.on.mostRecentCall.args[1](event);
|
||||
mockElement.on.calls.mostRecent().args[1](event);
|
||||
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||
testAttrs.mctDragDown,
|
||||
{ delta: [0, 0], $event: event }
|
||||
@@ -220,7 +220,7 @@ define(
|
||||
});
|
||||
|
||||
it("listens for mousemove after dragging begins", function () {
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
expect(mockBody.on).toHaveBeenCalledWith(
|
||||
"mousemove",
|
||||
jasmine.any(Function)
|
||||
@@ -234,10 +234,10 @@ define(
|
||||
it("invokes mctDrag expression during drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mousemove') {
|
||||
call.args[1](event = testEvent(52, 200));
|
||||
}
|
||||
@@ -253,16 +253,16 @@ define(
|
||||
it("invokes mctDragUp expression after drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mousemove') {
|
||||
call.args[1](testEvent(52, 200));
|
||||
}
|
||||
});
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mouseup') {
|
||||
call.args[1](event = testEvent(40, 71));
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ define(
|
||||
height: 75
|
||||
};
|
||||
|
||||
mockCompile.andCallFake(function () {
|
||||
mockCompile.and.callFake(function () {
|
||||
var mockFn = jasmine.createSpy();
|
||||
mockFn.andReturn(mockNewElement);
|
||||
mockFn.and.returnValue(mockNewElement);
|
||||
return mockFn;
|
||||
});
|
||||
mockElement.parent.andReturn([mockParentEl]);
|
||||
mockParentEl.getBoundingClientRect.andReturn(testRect);
|
||||
mockPopupService.display.andReturn(mockPopup);
|
||||
mockElement.parent.and.returnValue([mockParentEl]);
|
||||
mockParentEl.getBoundingClientRect.and.returnValue(testRect);
|
||||
mockPopupService.display.and.returnValue(mockPopup);
|
||||
|
||||
mctPopup = new MCTPopup(mockCompile, mockPopupService);
|
||||
|
||||
@@ -113,14 +113,14 @@ define(
|
||||
it("displays transcluded content", function () {
|
||||
var mockClone =
|
||||
jasmine.createSpyObj('clone', JQLITE_METHODS);
|
||||
mockTransclude.mostRecentCall.args[0](mockClone);
|
||||
mockTransclude.calls.mostRecent().args[0](mockClone);
|
||||
expect(mockNewElement.append)
|
||||
.toHaveBeenCalledWith(mockClone);
|
||||
});
|
||||
|
||||
it("is removed when its containing scope is destroyed", function () {
|
||||
expect(mockPopup.dismiss).not.toHaveBeenCalled();
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === '$destroy') {
|
||||
call.args[1]();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ define(
|
||||
);
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should have triggered an evaluation of mctResize
|
||||
// with the new width & height
|
||||
@@ -91,56 +91,56 @@ define(
|
||||
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||
|
||||
// Should have scheduled the first timeout
|
||||
expect(mockTimeout.calls.length).toEqual(1);
|
||||
expect(mockTimeout.calls.count()).toEqual(1);
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should have scheduled another timeout
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
|
||||
// Broadcast a destroy event
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
mockScope.$on.calls.mostRecent().args[1]();
|
||||
|
||||
testElement.offsetWidth = 300;
|
||||
testElement.offsetHeight = 350;
|
||||
mockScope.$eval.reset();
|
||||
mockScope.$eval.calls.reset();
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should NOT have scheduled another timeout
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
expect(mockScope.$eval).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("triggers a digest cycle when size changes", function () {
|
||||
var applyCount;
|
||||
mctResize.link(mockScope, [testElement], testAttrs);
|
||||
applyCount = mockScope.$apply.calls.length;
|
||||
applyCount = mockScope.$apply.calls.count();
|
||||
|
||||
// Change the element's apparent size
|
||||
testElement.offsetWidth = 300;
|
||||
testElement.offsetHeight = 350;
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// No more apply calls
|
||||
expect(mockScope.$apply.calls.length)
|
||||
expect(mockScope.$apply.calls.count())
|
||||
.toBeGreaterThan(applyCount);
|
||||
});
|
||||
|
||||
it("does not trigger a digest cycle when size does not change", function () {
|
||||
var applyCount;
|
||||
mctResize.link(mockScope, [testElement], testAttrs);
|
||||
applyCount = mockScope.$apply.calls.length;
|
||||
applyCount = mockScope.$apply.calls.count();
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// No more apply calls
|
||||
expect(mockScope.$apply.calls.length).toEqual(applyCount);
|
||||
expect(mockScope.$apply.calls.count()).toEqual(applyCount);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
mockElement = [{ testProperty: 42 }];
|
||||
mockElement.on = jasmine.createSpy('on');
|
||||
|
||||
mockParse.andReturn(mockParsed);
|
||||
mockParse.and.returnValue(mockParsed);
|
||||
|
||||
testAttrs = {};
|
||||
testAttrs[ATTRIBUTE] = EXPRESSION;
|
||||
@@ -76,7 +76,7 @@ define(
|
||||
jasmine.any(Function)
|
||||
);
|
||||
// Should have been only watch (other tests need this to be true)
|
||||
expect(mockScope.$watch.calls.length).toEqual(1);
|
||||
expect(mockScope.$watch.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("listens for scroll events", function () {
|
||||
@@ -85,7 +85,7 @@ define(
|
||||
jasmine.any(Function)
|
||||
);
|
||||
// Should have been only listener (other tests need this to be true)
|
||||
expect(mockElement.on.calls.length).toEqual(1);
|
||||
expect(mockElement.on.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("publishes initial scroll state", function () {
|
||||
@@ -94,13 +94,13 @@ define(
|
||||
});
|
||||
|
||||
it("updates scroll state when scope changes", function () {
|
||||
mockScope.$watch.mostRecentCall.args[1](64);
|
||||
mockScope.$watch.calls.mostRecent().args[1](64);
|
||||
expect(mockElement[0].testProperty).toEqual(64);
|
||||
});
|
||||
|
||||
it("updates scope when scroll state changes", function () {
|
||||
mockElement[0].testProperty = 12321;
|
||||
mockElement.on.mostRecentCall.args[1]({ target: mockElement[0] });
|
||||
mockElement.on.calls.mostRecent().args[1]({ target: mockElement[0] });
|
||||
expect(mockParsed.assign).toHaveBeenCalledWith(mockScope, 12321);
|
||||
expect(mockScope.$apply).toHaveBeenCalledWith(EXPRESSION);
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
mockInterval.cancel = jasmine.createSpy('mockCancel');
|
||||
mockParsed = jasmine.createSpy('parsed');
|
||||
mockParsed.assign = jasmine.createSpy('assign');
|
||||
mockParse.andReturn(mockParsed);
|
||||
mockParse.and.returnValue(mockParsed);
|
||||
|
||||
mockWindow.localStorage = {
|
||||
store: {},
|
||||
@@ -84,7 +84,7 @@ define(
|
||||
controller;
|
||||
|
||||
function fireOn(eventType) {
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === eventType) {
|
||||
call.args[1]();
|
||||
}
|
||||
@@ -106,12 +106,12 @@ define(
|
||||
mockSecondPane =
|
||||
jasmine.createSpyObj('secondPane', JQLITE_METHODS);
|
||||
|
||||
mockElement.children.andReturn(mockChildren);
|
||||
mockElement.children.and.returnValue(mockChildren);
|
||||
mockElement[0] = {
|
||||
offsetWidth: 12321,
|
||||
offsetHeight: 45654
|
||||
};
|
||||
mockChildren.eq.andCallFake(function (i) {
|
||||
mockChildren.eq.and.callFake(function (i) {
|
||||
return [mockFirstPane, mockSplitter, mockSecondPane][i];
|
||||
});
|
||||
mockFirstPane[0] = { offsetWidth: 123, offsetHeight: 456 };
|
||||
@@ -135,7 +135,7 @@ define(
|
||||
});
|
||||
|
||||
it("sets an interval which does not trigger digests", function () {
|
||||
expect(mockInterval.mostRecentCall.args[3]).toBe(false);
|
||||
expect(mockInterval.calls.mostRecent().args[3]).toBe(false);
|
||||
});
|
||||
|
||||
it("exposes its splitter's initial position", function () {
|
||||
@@ -202,7 +202,7 @@ define(
|
||||
expect(controller.position()).not.toEqual(
|
||||
mockFirstPane[0].offsetWidth
|
||||
);
|
||||
mockInterval.mostRecentCall.args[0]();
|
||||
mockInterval.calls.mostRecent().args[0]();
|
||||
expect(controller.position()).toEqual(
|
||||
mockFirstPane[0].offsetWidth
|
||||
);
|
||||
|
||||
@@ -78,8 +78,8 @@ define(
|
||||
|
||||
beforeEach(function () {
|
||||
testPosition = 12321;
|
||||
mockSplitPane.position.andReturn(testPosition);
|
||||
mockSplitPane.anchor.andReturn({
|
||||
mockSplitPane.position.and.returnValue(testPosition);
|
||||
mockSplitPane.anchor.and.returnValue({
|
||||
orientation: 'vertical',
|
||||
reversed: false
|
||||
});
|
||||
|
||||
@@ -38,8 +38,8 @@ define([
|
||||
'getCapability',
|
||||
'hasCapability'
|
||||
]);
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockDomainObject.getModel.andReturn({});
|
||||
mockDomainObject.getId.and.returnValue(id);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
return mockDomainObject;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ define([
|
||||
mockParse = jasmine.createSpy('$parse');
|
||||
mockExpr = jasmine.createSpy('expr');
|
||||
mockExpr.assign = jasmine.createSpy('assign');
|
||||
mockParse.andReturn(mockExpr);
|
||||
spyOn(TreeView.prototype, 'observe').andCallThrough();
|
||||
mockParse.and.returnValue(mockExpr);
|
||||
spyOn(TreeView.prototype, 'observe').and.callThrough();
|
||||
|
||||
mctTree = new MCTTree(mockParse, mockGestureService);
|
||||
});
|
||||
@@ -118,7 +118,7 @@ define([
|
||||
it("does not trigger $apply during $watches", function () {
|
||||
mockScope.mctObject = makeMockDomainObject('root');
|
||||
mockScope.mctMode = makeMockDomainObject('selection');
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
call.args[1](mockScope[call.args[0]]);
|
||||
});
|
||||
expect(mockScope.$apply).not.toHaveBeenCalled();
|
||||
@@ -129,7 +129,7 @@ define([
|
||||
return;
|
||||
}
|
||||
// White-boxy; we know this is the setter for the tree's value
|
||||
var treeValueFn = TreeView.prototype.observe.calls[0].args[0];
|
||||
var treeValueFn = TreeView.prototype.observe.calls.all()[0].args[0];
|
||||
|
||||
mockScope.mctObject = makeMockDomainObject('root');
|
||||
mockScope.mctMode = makeMockDomainObject('selection');
|
||||
|
||||
Reference in New Issue
Block a user