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
@@ -45,7 +45,7 @@ define(
|
||||
mockTimeout = jasmine.createSpy('$timeout');
|
||||
mockDocument = jasmine.createSpyObj('$document', ['find']);
|
||||
mockBody = jasmine.createSpyObj('body', ['on', 'off', 'scope', 'css', 'unbind']);
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
|
||||
mockInfoService = jasmine.createSpyObj(
|
||||
'infoService',
|
||||
@@ -68,14 +68,14 @@ define(
|
||||
testMetadata = [{ name: "Test name", value: "Test value" }];
|
||||
mockHide = jasmine.createSpy('hide');
|
||||
|
||||
mockDomainObject.getModel.andReturn({ name: "Test Object" });
|
||||
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||
mockDomainObject.getModel.and.returnValue({ name: "Test Object" });
|
||||
mockDomainObject.useCapability.and.callFake(function (c) {
|
||||
return (c === 'metadata') ? testMetadata : undefined;
|
||||
});
|
||||
mockElement.scope.andReturn(mockScope);
|
||||
mockScope.$on.andReturn(mockOff);
|
||||
mockInfoService.display.andReturn(mockHide);
|
||||
mockAgentService.isMobile.andReturn(true);
|
||||
mockElement.scope.and.returnValue(mockScope);
|
||||
mockScope.$on.and.returnValue(mockOff);
|
||||
mockInfoService.display.and.returnValue(mockHide);
|
||||
mockAgentService.isMobile.and.returnValue(true);
|
||||
gesture = new InfoButtonGesture(
|
||||
mockDocument,
|
||||
mockAgentService,
|
||||
@@ -83,7 +83,7 @@ define(
|
||||
mockElement,
|
||||
mockDomainObject
|
||||
);
|
||||
fireGesture = mockElement.on.mostRecentCall.args[1];
|
||||
fireGesture = mockElement.on.calls.mostRecent().args[1];
|
||||
});
|
||||
|
||||
it("expect click on the representation", function () {
|
||||
@@ -106,7 +106,7 @@ define(
|
||||
|
||||
// Get the touch start on the body
|
||||
// and fire the dismiss gesture
|
||||
fireDismissGesture = mockBody.on.mostRecentCall.args[1];
|
||||
fireDismissGesture = mockBody.on.calls.mostRecent().args[1];
|
||||
fireDismissGesture(mockEvent);
|
||||
// Expect Body to have been touched, event.preventDefault()
|
||||
// to be called, then the mockBody listener to be detached
|
||||
|
||||
@@ -39,7 +39,7 @@ define(
|
||||
gesture;
|
||||
|
||||
function fireEvent(evt, value) {
|
||||
mockElement.on.calls.forEach(function (call) {
|
||||
mockElement.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === evt) {
|
||||
call.args[1](value);
|
||||
}
|
||||
@@ -68,14 +68,14 @@ define(
|
||||
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||
mockHide = jasmine.createSpy('hide');
|
||||
|
||||
mockDomainObject.getModel.andReturn({ name: "Test Object" });
|
||||
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||
mockDomainObject.getModel.and.returnValue({ name: "Test Object" });
|
||||
mockDomainObject.useCapability.and.callFake(function (c) {
|
||||
return (c === 'metadata') ? testMetadata : undefined;
|
||||
});
|
||||
mockElement.scope.andReturn(mockScope);
|
||||
mockScope.$on.andReturn(mockOff);
|
||||
mockTimeout.andReturn(mockPromise);
|
||||
mockInfoService.display.andReturn(mockHide);
|
||||
mockElement.scope.and.returnValue(mockScope);
|
||||
mockScope.$on.and.returnValue(mockOff);
|
||||
mockTimeout.and.returnValue(mockPromise);
|
||||
mockInfoService.display.and.returnValue(mockHide);
|
||||
|
||||
gesture = new InfoGesture(
|
||||
mockTimeout,
|
||||
@@ -96,7 +96,7 @@ define(
|
||||
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
||||
expect(mockTimeout)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function), testDelay);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockInfoService.display).toHaveBeenCalledWith(
|
||||
jasmine.any(String),
|
||||
"Test Object",
|
||||
@@ -114,7 +114,7 @@ define(
|
||||
|
||||
it("hides a shown bubble when mouse leaves", function () {
|
||||
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockHide).not.toHaveBeenCalled(); // verify precondition
|
||||
fireEvent("mouseleave", {});
|
||||
expect(mockHide).toHaveBeenCalled();
|
||||
@@ -124,7 +124,7 @@ define(
|
||||
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
||||
fireEvent("mousemove", { clientX: 1999, clientY: 11 });
|
||||
fireEvent("mousemove", { clientX: 1984, clientY: 11 });
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
// Should have displayed at the latest observed mouse position
|
||||
expect(mockInfoService.display).toHaveBeenCalledWith(
|
||||
jasmine.any(String),
|
||||
@@ -136,7 +136,7 @@ define(
|
||||
|
||||
it("hides shown bubbles when destroyed", function () {
|
||||
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockHide).not.toHaveBeenCalled(); // verify precondition
|
||||
gesture.destroy();
|
||||
expect(mockHide).toHaveBeenCalled();
|
||||
@@ -145,7 +145,7 @@ define(
|
||||
it("detaches listeners when destroyed", function () {
|
||||
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
||||
gesture.destroy();
|
||||
mockElement.on.calls.forEach(function (call) {
|
||||
mockElement.on.calls.all().forEach(function (call) {
|
||||
expect(mockElement.off).toHaveBeenCalledWith(
|
||||
call.args[0],
|
||||
call.args[1]
|
||||
|
||||
@@ -53,19 +53,19 @@ define(
|
||||
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
||||
mockElements = [];
|
||||
|
||||
mockPopupService.display.andReturn(mockPopup);
|
||||
mockCompile.andCallFake(function () {
|
||||
mockPopupService.display.and.returnValue(mockPopup);
|
||||
mockCompile.and.callFake(function () {
|
||||
var mockCompiledTemplate = jasmine.createSpy('template'),
|
||||
mockElement = jasmine.createSpyObj('element', [
|
||||
'css',
|
||||
'remove',
|
||||
'append'
|
||||
]);
|
||||
mockCompiledTemplate.andReturn(mockElement);
|
||||
mockCompiledTemplate.and.returnValue(mockElement);
|
||||
mockElements.push(mockElement);
|
||||
return mockCompiledTemplate;
|
||||
});
|
||||
mockRootScope.$new.andReturn(mockScope);
|
||||
mockRootScope.$new.and.returnValue(mockScope);
|
||||
|
||||
service = new InfoService(
|
||||
mockCompile,
|
||||
@@ -92,7 +92,7 @@ define(
|
||||
});
|
||||
|
||||
it("when on phone device, positions at bottom", function () {
|
||||
mockAgentService.isPhone.andReturn(true);
|
||||
mockAgentService.isPhone.and.returnValue(true);
|
||||
service = new InfoService(
|
||||
mockCompile,
|
||||
mockRootScope,
|
||||
@@ -119,10 +119,10 @@ define(
|
||||
].join('-');
|
||||
|
||||
beforeEach(function () {
|
||||
mockPopup.goesUp.andReturn(goesUp);
|
||||
mockPopup.goesDown.andReturn(!goesUp);
|
||||
mockPopup.goesLeft.andReturn(goesLeft);
|
||||
mockPopup.goesRight.andReturn(!goesLeft);
|
||||
mockPopup.goesUp.and.returnValue(goesUp);
|
||||
mockPopup.goesDown.and.returnValue(!goesUp);
|
||||
mockPopup.goesLeft.and.returnValue(goesLeft);
|
||||
mockPopup.goesRight.and.returnValue(!goesLeft);
|
||||
service.display('', '', {}, [10, 10]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user