diff --git a/karma.conf.js b/karma.conf.js index 085d3b3a00..660acf3ac5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -65,7 +65,7 @@ module.exports = function(config) { // Test results reporter to use // Possible values: 'dots', 'progress' // Available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress', 'coverage', 'html', 'junit'], + reporters: ['progress', 'coverage', 'html'], // Web server port. port: 9876, @@ -81,7 +81,7 @@ module.exports = function(config) { // Specify browsers to run tests in. // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: [ - 'Chrome' + 'ChromeHeadless' ], // Code coverage reporting. @@ -104,10 +104,6 @@ module.exports = function(config) { foldAll: false }, - junitReporter: { - outputDir: process.env.CIRCLE_TEST_REPORTS || 'dist/reports/junit' - }, - // Continuous Integration mode. // If true, Karma captures browsers, runs the tests and exits. singleRun: true diff --git a/package.json b/package.json index 6742214a47..d6256351d8 100644 --- a/package.json +++ b/package.json @@ -32,18 +32,17 @@ "gulp-sass": "^3.1.0", "gulp-sourcemaps": "^1.6.0", "html2canvas": "^1.0.0-alpha.12", - "jasmine-core": "^2.3.0", + "jasmine-core": "^3.1.0", "jscs-html-reporter": "^0.1.0", "jsdoc": "^3.3.2", "jshint": "^2.7.0", - "karma": "^0.13.3", - "karma-chrome-launcher": "^0.1.12", - "karma-cli": "0.0.4", - "karma-coverage": "^0.5.3", + "karma": "^2.0.3", + "karma-chrome-launcher": "^2.2.0", + "karma-cli": "^1.0.1", + "karma-coverage": "^1.1.2", "karma-html-reporter": "^0.2.7", - "karma-jasmine": "^0.1.5", - "karma-junit-reporter": "^0.3.8", - "karma-requirejs": "^0.2.2", + "karma-jasmine": "^1.1.2", + "karma-requirejs": "^1.1.0", "lodash": "^3.10.1", "markdown-toc": "^0.11.7", "marked": "^0.3.5", diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index d979d14d1a..20b20805a6 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -19,6 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ +/*global console*/ /** * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. @@ -48,9 +49,19 @@ define( controller; function waitsForNavigation() { - var calls = mockNavigationService.setNavigation.calls.length; - waitsFor(function () { - return mockNavigationService.setNavigation.calls.length > calls; + return new Promise(function (resolve) { + mockNavigationService.setNavigation.and.callFake(function (obj) { + var returnValue; + try { + returnValue = NavigationService.prototype.setNavigation.call(mockNavigationService, obj); + } catch (err) { + console.error(err); + //Not rejecting because 'setNavigation' has been called, which is what's being tested here. + //Rejecting will fail tests. + } + resolve(); + return returnValue; + }); }); } @@ -78,7 +89,7 @@ define( "urlService", ["urlForLocation"] ); - mockUrlService.urlForLocation.andCallFake(function (mode, object) { + mockUrlService.urlForLocation.and.callFake(function (mode, object) { if (object === mockDefaultRootObject) { return [mode, testDefaultRoot].join('/'); } @@ -106,7 +117,7 @@ define( "removeListener" ].forEach(function (method) { spyOn(mockNavigationService, method) - .andCallThrough(); + .and.callThrough(); }); mockRootObject = jasmine.createSpyObj( "rootObjectContainer", @@ -124,60 +135,58 @@ define( "nestedDomainObject", ["getId", "getCapability", "getModel", "useCapability", "hasCapability"] ); - mockObjectService.getObjects.andReturn(Promise.resolve({ + mockObjectService.getObjects.and.returnValue(Promise.resolve({ ROOT: mockRootObject })); - mockRootObject.useCapability.andReturn(Promise.resolve([ + mockRootObject.useCapability.and.returnValue(Promise.resolve([ mockOtherDomainObject, mockDefaultRootObject ])); - mockRootObject.hasCapability.andReturn(true); - mockDefaultRootObject.useCapability.andReturn(Promise.resolve([ + mockRootObject.hasCapability.and.returnValue(true); + mockDefaultRootObject.useCapability.and.returnValue(Promise.resolve([ mockNextObject ])); - mockDefaultRootObject.hasCapability.andReturn(true); - mockOtherDomainObject.hasCapability.andReturn(false); - mockNextObject.useCapability.andReturn(undefined); - mockNextObject.hasCapability.andReturn(false); - mockNextObject.getId.andReturn("next"); - mockDefaultRootObject.getId.andReturn(testDefaultRoot); + mockDefaultRootObject.hasCapability.and.returnValue(true); + mockOtherDomainObject.hasCapability.and.returnValue(false); + mockNextObject.useCapability.and.returnValue(undefined); + mockNextObject.hasCapability.and.returnValue(false); + mockNextObject.getId.and.returnValue("next"); + mockDefaultRootObject.getId.and.returnValue(testDefaultRoot); instantiateController(); - waitsForNavigation(); + return waitsForNavigation(); }); it("uses composition to set the navigated object, if there is none", function () { instantiateController(); - waitsForNavigation(); - runs(function () { + return waitsForNavigation().then(function () { expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockDefaultRootObject); + .toHaveBeenCalledWith(mockDefaultRootObject); }); }); it("navigates to a root-level object, even when default path is not found", function () { mockDefaultRootObject.getId - .andReturn("something-other-than-the-" + testDefaultRoot); + .and.returnValue("something-other-than-the-" + testDefaultRoot); instantiateController(); - waitsForNavigation(); - runs(function () { + return waitsForNavigation().then(function () { expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockDefaultRootObject); + .toHaveBeenCalledWith(mockDefaultRootObject); }); + }); - }); - // it("does not try to override navigation", function () { - mockNavigationService.getNavigation.andReturn(mockDefaultRootObject); + mockNavigationService.getNavigation.and.returnValue(mockDefaultRootObject); instantiateController(); - waitsForNavigation(); - expect(mockScope.navigatedObject).toBe(mockDefaultRootObject); + return waitsForNavigation().then(function () { + expect(mockScope.navigatedObject).toBe(mockDefaultRootObject); + }); }); - // + it("updates scope when navigated object changes", function () { // Should have registered a listener - call it - mockNavigationService.addListener.mostRecentCall.args[0]( + mockNavigationService.addListener.calls.mostRecent().args[0]( mockOtherDomainObject ); expect(mockScope.navigatedObject).toEqual(mockOtherDomainObject); @@ -189,19 +198,18 @@ define( "$destroy", jasmine.any(Function) ); - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); // Should remove the listener it added earlier expect(mockNavigationService.removeListener).toHaveBeenCalledWith( - mockNavigationService.addListener.mostRecentCall.args[0] + mockNavigationService.addListener.calls.mostRecent().args[0] ); }); it("uses route parameters to choose initially-navigated object", function () { mockRoute.current.params.ids = testDefaultRoot + "/next"; instantiateController(); - waitsForNavigation(); - runs(function () { + return waitsForNavigation().then(function () { expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockNextObject); @@ -214,12 +222,10 @@ define( // it hits an invalid ID. mockRoute.current.params.ids = testDefaultRoot + "/junk"; instantiateController(); - waitsForNavigation(); - runs(function () { + return waitsForNavigation().then(function () { expect(mockScope.navigatedObject).toBe(mockDefaultRootObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockDefaultRootObject); - }); }); @@ -229,8 +235,7 @@ define( // should stop at it since remaining IDs cannot be loaded. mockRoute.current.params.ids = testDefaultRoot + "/next/junk"; instantiateController(); - waitsForNavigation(); - runs(function () { + return waitsForNavigation().then(function () { expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockNextObject); @@ -244,11 +249,11 @@ define( expect(mockRoute.current.pathParams.ids) .not .toBe(testDefaultRoot + '/next'); - mockLocation.path.andCallFake(function () { + mockLocation.path.and.callFake(function () { expect(mockRoute.current.pathParams.ids) .toBe(testDefaultRoot + '/next'); }); - mockNavigationService.addListener.mostRecentCall.args[0]( + mockNavigationService.addListener.calls.mostRecent().args[0]( mockNextObject ); expect(mockLocation.path).toHaveBeenCalledWith( diff --git a/platform/commonUI/browse/test/BrowseObjectControllerSpec.js b/platform/commonUI/browse/test/BrowseObjectControllerSpec.js index b55c0a12b0..5a5db6f4fb 100644 --- a/platform/commonUI/browse/test/BrowseObjectControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseObjectControllerSpec.js @@ -20,7 +20,6 @@ * at runtime from the About dialog for additional information. *****************************************************************************/ - define( ["../src/BrowseObjectController"], function (BrowseObjectController) { @@ -33,7 +32,7 @@ define( // Utility function; look for a $watch on scope and fire it function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -50,7 +49,7 @@ define( "$location", ["path", "search"] ); - mockLocation.search.andReturn({}); + mockLocation.search.and.returnValue({}); controller = new BrowseObjectController( mockScope, @@ -65,7 +64,7 @@ define( // Allows the path index to be checked // prior to setting $route.current - mockLocation.path.andReturn("/browse/"); + mockLocation.path.and.returnValue("/browse/"); }); it("sets the active view from query parameters", function () { @@ -79,10 +78,10 @@ define( { key: 'xyz' } ]; - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return (c === 'view') && testViews; }); - mockLocation.search.andReturn({ view: 'def' }); + mockLocation.search.and.returnValue({ view: 'def' }); fireWatch('domainObject', mockDomainObject); expect(mockScope.representation.selected) diff --git a/platform/commonUI/browse/test/InspectorPaneControllerSpec.js b/platform/commonUI/browse/test/InspectorPaneControllerSpec.js index 016e88ecf5..ca2947a882 100644 --- a/platform/commonUI/browse/test/InspectorPaneControllerSpec.js +++ b/platform/commonUI/browse/test/InspectorPaneControllerSpec.js @@ -50,14 +50,14 @@ define( "navigationService", ["getNavigation", "addListener"] ); - mockNavigationService.addListener.andReturn(mockNavigationUnlistener); + mockNavigationService.addListener.and.returnValue(mockNavigationUnlistener); mockStatusUnlistener = jasmine.createSpy("statusUnlistener"); mockStatusCapability = jasmine.createSpyObj( "statusCapability", ["listen"] ); - mockStatusCapability.listen.andReturn(mockStatusUnlistener); + mockStatusCapability.listen.and.returnValue(mockStatusUnlistener); mockDomainObject = jasmine.createSpyObj( 'domainObject', @@ -68,13 +68,13 @@ define( 'hasCapability' ] ); - mockDomainObject.getId.andReturn("domainObject"); - mockDomainObject.getModel.andReturn({}); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andReturn(mockStatusCapability); + mockDomainObject.getId.and.returnValue("domainObject"); + mockDomainObject.getModel.and.returnValue({}); + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.returnValue(mockStatusCapability); mockLocation = jasmine.createSpyObj('location', ['search']); - mockLocation.search.andReturn({}); + mockLocation.search.and.returnValue({}); mockAttrs = {}; @@ -84,7 +84,7 @@ define( it("listens for changes to navigation and attaches a status" + " listener", function () { expect(mockNavigationService.addListener).toHaveBeenCalledWith(jasmine.any(Function)); - mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); + mockNavigationService.addListener.calls.mostRecent().args[0](mockDomainObject); expect(mockStatusCapability.listen).toHaveBeenCalledWith(jasmine.any(Function)); }); @@ -93,8 +93,8 @@ define( controller.toggle(); // test pre-condition that inspector is hidden expect(controller.visible()).toBe(false); - mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); - mockStatusCapability.listen.mostRecentCall.args[0](["editing"]); + mockNavigationService.addListener.calls.mostRecent().args[0](mockDomainObject); + mockStatusCapability.listen.calls.mostRecent().args[0](["editing"]); expect(controller.visible()).toBe(true); }); diff --git a/platform/commonUI/browse/test/MenuArrowControllerSpec.js b/platform/commonUI/browse/test/MenuArrowControllerSpec.js index 5d3bca7839..6a58645f63 100644 --- a/platform/commonUI/browse/test/MenuArrowControllerSpec.js +++ b/platform/commonUI/browse/test/MenuArrowControllerSpec.js @@ -60,8 +60,8 @@ define( mockActionContext.domainObject = mockDomainObject; mockActionContext.event = mockEvent; mockScope.domainObject = mockDomainObject; - mockDomainObject.getCapability.andReturn(mockContextMenuAction); - mockContextMenuAction.perform.andReturn(jasmine.any(Function)); + mockDomainObject.getCapability.and.returnValue(mockContextMenuAction); + mockContextMenuAction.perform.and.returnValue(jasmine.any(Function)); controller = new MenuArrowController(mockScope); }); diff --git a/platform/commonUI/browse/test/ObjectHeaderControllerSpec.js b/platform/commonUI/browse/test/ObjectHeaderControllerSpec.js index 172b693890..37281b2bec 100644 --- a/platform/commonUI/browse/test/ObjectHeaderControllerSpec.js +++ b/platform/commonUI/browse/test/ObjectHeaderControllerSpec.js @@ -39,7 +39,7 @@ define( mockMutationCapability = jasmine.createSpyObj("mutation", ["mutate"]); mockTypeCapability = jasmine.createSpyObj("type", ["typeDef", "hasFeature"]); mockTypeCapability.typeDef = { name: ""}; - mockTypeCapability.hasFeature.andCallFake(function (feature) { + mockTypeCapability.hasFeature.and.callFake(function (feature) { return feature === 'creation'; }); @@ -52,8 +52,8 @@ define( name: "Test name" }; mockDomainObject = jasmine.createSpyObj("domainObject", ["getCapability", "getModel"]); - mockDomainObject.getModel.andReturn(model); - mockDomainObject.getCapability.andCallFake(function (key) { + mockDomainObject.getModel.and.returnValue(model); + mockDomainObject.getCapability.and.callFake(function (key) { return mockCapabilities[key]; }); @@ -62,7 +62,7 @@ define( }; mockCurrentTarget = jasmine.createSpyObj("currentTarget", ["blur", "textContent"]); - mockCurrentTarget.blur.andReturn(mockCurrentTarget); + mockCurrentTarget.blur.and.returnValue(mockCurrentTarget); mockEvent = { which: {}, @@ -109,7 +109,7 @@ define( expect(mockMutationCapability.mutate).toHaveBeenCalledWith(jasmine.any(Function)); - mockMutationCapability.mutate.mostRecentCall.args[0](model); + mockMutationCapability.mutate.calls.mostRecent().args[0](model); expect(mockDomainObject.getModel().name).toBe("New name"); }); @@ -127,7 +127,7 @@ define( }); it("disallows editting name when object is non-creatable", function () { - mockTypeCapability.hasFeature.andReturn(false); + mockTypeCapability.hasFeature.and.returnValue(false); expect(controller.allowEdit()).toBe(false); diff --git a/platform/commonUI/browse/test/PaneControllerSpec.js b/platform/commonUI/browse/test/PaneControllerSpec.js index e68eb84406..94ec29c417 100644 --- a/platform/commonUI/browse/test/PaneControllerSpec.js +++ b/platform/commonUI/browse/test/PaneControllerSpec.js @@ -53,8 +53,8 @@ define( ['getId', 'getModel', 'getCapability'] ); - mockDomainObject.getId.andReturn(id); - mockDomainObject.getModel.andReturn({}); + mockDomainObject.getId.and.returnValue(id); + mockDomainObject.getModel.and.returnValue({}); return mockDomainObject; }); @@ -65,7 +65,7 @@ define( mockWindow = jasmine.createSpyObj("$window", ["open"]); mockLocation = jasmine.createSpyObj('location', ['search']); - mockLocation.search.andReturn({}); + mockLocation.search.and.returnValue({}); mockAttrs = {}; }); @@ -83,9 +83,9 @@ define( }); it("collapses on navigation changes on portrait-oriented phones", function () { - mockAgentService.isMobile.andReturn(true); - mockAgentService.isPhone.andReturn(true); - mockAgentService.isPortrait.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); + mockAgentService.isPhone.and.returnValue(true); + mockAgentService.isPortrait.and.returnValue(true); controller = instantiateController(); expect(controller.visible()).toBeTruthy(); @@ -102,13 +102,13 @@ define( }); it("sets pane state to false when in location.search", function () { - mockLocation.search.andReturn({'hideTree': true}); + mockLocation.search.and.returnValue({'hideTree': true}); expect(instantiateController().visible()).toBe(false); expect(mockLocation.search).toHaveBeenCalledWith('hideTree', undefined); }); it("sets state to true when not found in location.search", function () { - mockLocation.search.andReturn({}); + mockLocation.search.and.returnValue({}); expect(instantiateController().visible()).toBe(true); expect(mockLocation.search).not.toHaveBeenCalledWith('hideTree', undefined); }); diff --git a/platform/commonUI/browse/test/navigation/NavigateActionSpec.js b/platform/commonUI/browse/test/navigation/NavigateActionSpec.js index 0091006057..7505d8da10 100644 --- a/platform/commonUI/browse/test/navigation/NavigateActionSpec.js +++ b/platform/commonUI/browse/test/navigation/NavigateActionSpec.js @@ -34,17 +34,6 @@ define([ mockDomainObject, action; - - function waitForCall() { - var called = false; - waitsFor(function () { - return called; - }); - return function () { - called = true; - }; - } - beforeEach(function () { mockNavigationService = jasmine.createSpyObj( "navigationService", @@ -63,26 +52,24 @@ define([ }); it("sets navigation if it is allowed", function () { - mockNavigationService.shouldNavigate.andReturn(true); - action.perform() - .then(waitForCall()); - runs(function () { - expect(mockNavigationService.setNavigation) + mockNavigationService.shouldNavigate.and.returnValue(true); + return action.perform() + .then(function () { + expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockDomainObject, true); - }); + }); }); it("does not set navigation if it is not allowed", function () { - mockNavigationService.shouldNavigate.andReturn(false); + mockNavigationService.shouldNavigate.and.returnValue(false); var onSuccess = jasmine.createSpy('onSuccess'); - action.perform() - .then(onSuccess, waitForCall()); - runs(function () { - expect(onSuccess).not.toHaveBeenCalled(); - expect(mockNavigationService.setNavigation) - .not - .toHaveBeenCalledWith(mockDomainObject); - }); + return action.perform() + .then(onSuccess, function () { + expect(onSuccess).not.toHaveBeenCalled(); + expect(mockNavigationService.setNavigation) + .not + .toHaveBeenCalledWith(mockDomainObject); + }); }); it("is only applicable when a domain object is in context", function () { diff --git a/platform/commonUI/browse/test/navigation/NavigationServiceSpec.js b/platform/commonUI/browse/test/navigation/NavigationServiceSpec.js index 3e9f2182d7..418660ca00 100644 --- a/platform/commonUI/browse/test/navigation/NavigationServiceSpec.js +++ b/platform/commonUI/browse/test/navigation/NavigationServiceSpec.js @@ -69,7 +69,7 @@ define( navigationService.addListener(callback); navigationService.setNavigation(testObject); navigationService.setNavigation(testObject); - expect(callback.calls.length).toEqual(1); + expect(callback.calls.count()).toEqual(1); }); it("stops notifying listeners after removal", function () { diff --git a/platform/commonUI/browse/test/navigation/OrphanNavigationHandlerSpec.js b/platform/commonUI/browse/test/navigation/OrphanNavigationHandlerSpec.js index ce796a74c0..f29a32e0a5 100644 --- a/platform/commonUI/browse/test/navigation/OrphanNavigationHandlerSpec.js +++ b/platform/commonUI/browse/test/navigation/OrphanNavigationHandlerSpec.js @@ -65,34 +65,35 @@ define([ mockActionCapability = jasmine.createSpyObj('action', ['perform']); mockEditor = jasmine.createSpyObj('editor', ['isEditContextRoot']); - mockThrottle.andCallFake(function (fn) { + mockThrottle.and.callFake(function (fn) { var mockThrottledFn = jasmine.createSpy('throttled-' + mockThrottledFns.length); - mockThrottledFn.andCallFake(fn); + mockThrottledFn.and.callFake(fn); mockThrottledFns.push(mockThrottledFn); return mockThrottledFn; }); - mockTopic.andReturn(mockMutationTopic); - mockDomainObject.getId.andReturn(testId); - mockDomainObject.getCapability.andCallFake(function (c) { + mockTopic.and.returnValue(mockMutationTopic); + mockDomainObject.getId.and.returnValue(testId); + mockDomainObject.getCapability.and.callFake(function (c) { return { context: mockContext, editor: mockEditor }[c]; }); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return !!mockDomainObject.getCapability(c); }); - mockParentObject.getCapability.andCallFake(function (c) { + mockParentObject.getCapability.and.callFake(function (c) { return { action: mockActionCapability }[c]; }); testParentComposition = []; - mockParentObject.useCapability.andReturn(Promise.resolve(testParentComposition)); - mockContext.getParent.andReturn(mockParentObject); - mockNavigationService.getNavigation.andReturn(mockDomainObject); - mockEditor.isEditContextRoot.andReturn(false); + mockParentObject.useCapability.and.returnValue(Promise.resolve(testParentComposition)); + + mockContext.getParent.and.returnValue(mockParentObject); + mockNavigationService.getNavigation.and.returnValue(mockDomainObject); + mockEditor.isEditContextRoot.and.returnValue(false); return new OrphanNavigationHandler( mockThrottle, @@ -106,7 +107,7 @@ define([ expect(mockMutationTopic.listen) .toHaveBeenCalledWith(jasmine.any(Function)); expect(mockThrottledFns.indexOf( - mockMutationTopic.listen.mostRecentCall.args[0] + mockMutationTopic.listen.calls.mostRecent().args[0] )).not.toEqual(-1); }); @@ -114,7 +115,7 @@ define([ expect(mockNavigationService.addListener) .toHaveBeenCalledWith(jasmine.any(Function)); expect(mockThrottledFns.indexOf( - mockNavigationService.addListener.mostRecentCall.args[0] + mockNavigationService.addListener.calls.mostRecent().args[0] )).not.toEqual(-1); }); @@ -134,28 +135,14 @@ define([ function itNavigatesAsExpected() { if (isOrphan && !isEditRoot) { it("navigates to the parent", function () { - var done = false; - waitsFor(function () { - return done; - }); - setTimeout(function () { - done = true; - }, 5); - runs(function () { + return Promise.resolve().then(function () { expect(mockActionCapability.perform) .toHaveBeenCalledWith('navigate'); }); }); } else { it("does nothing", function () { - var done = false; - waitsFor(function () { - return done; - }); - setTimeout(function () { - done = true; - }, 5); - runs(function () { + return Promise.resolve().then(function () { expect(mockActionCapability.perform) .not.toHaveBeenCalled(); }); @@ -165,12 +152,12 @@ define([ describe(caseName, function () { beforeEach(function () { - mockEditor.isEditContextRoot.andReturn(isEditRoot); + mockEditor.isEditContextRoot.and.returnValue(isEditRoot); }); describe("when navigation changes", function () { beforeEach(function () { - mockNavigationService.addListener.mostRecentCall + mockNavigationService.addListener.calls.mostRecent() .args[0](mockDomainObject); }); itNavigatesAsExpected(); @@ -178,7 +165,7 @@ define([ describe("when mutation occurs", function () { beforeEach(function () { - mockMutationTopic.listen.mostRecentCall + mockMutationTopic.listen.calls.mostRecent() .args[0](mockParentObject); }); diff --git a/platform/commonUI/browse/test/windowing/WindowTitlerSpec.js b/platform/commonUI/browse/test/windowing/WindowTitlerSpec.js index 436b09b8da..ec1f6920c6 100644 --- a/platform/commonUI/browse/test/windowing/WindowTitlerSpec.js +++ b/platform/commonUI/browse/test/windowing/WindowTitlerSpec.js @@ -49,8 +49,8 @@ define( ); mockDocument = [{}]; - mockDomainObject.getModel.andReturn({ name: 'Test name' }); - mockNavigationService.getNavigation.andReturn(mockDomainObject); + mockDomainObject.getModel.and.returnValue({ name: 'Test name' }); + mockNavigationService.getNavigation.and.returnValue(mockDomainObject); titler = new WindowTitler( mockNavigationService, @@ -64,12 +64,12 @@ define( jasmine.any(Function), jasmine.any(Function) ); - expect(mockRootScope.$watch.mostRecentCall.args[0]()) + expect(mockRootScope.$watch.calls.mostRecent().args[0]()) .toEqual('Test name'); }); it("sets the title to the name of the navigated object", function () { - mockRootScope.$watch.mostRecentCall.args[1]("Some name"); + mockRootScope.$watch.calls.mostRecent().args[1]("Some name"); expect(mockDocument[0].title).toEqual("Some name"); }); diff --git a/platform/commonUI/dialog/test/DialogServiceSpec.js b/platform/commonUI/dialog/test/DialogServiceSpec.js index 0945c7fd3a..85347cf2f3 100644 --- a/platform/commonUI/dialog/test/DialogServiceSpec.js +++ b/platform/commonUI/dialog/test/DialogServiceSpec.js @@ -63,12 +63,12 @@ define( ["find"] ); mockBody = jasmine.createSpyObj('body', ['on', 'off']); - mockDocument.find.andReturn(mockBody); + mockDocument.find.and.returnValue(mockBody); mockDeferred.promise = "mock promise"; - mockQ.defer.andReturn(mockDeferred); - mockOverlayService.createOverlay.andReturn(mockOverlay); + mockQ.defer.and.returnValue(mockDeferred); + mockOverlayService.createOverlay.and.returnValue(mockOverlay); dialogService = new DialogService( mockOverlayService, @@ -85,7 +85,7 @@ define( it("allows user input to be canceled", function () { dialogService.getUserInput({}, { someKey: "some value" }); - mockOverlayService.createOverlay.mostRecentCall.args[1].cancel(); + mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel(); expect(mockDeferred.reject).toHaveBeenCalled(); expect(mockDeferred.resolve).not.toHaveBeenCalled(); }); @@ -93,7 +93,7 @@ define( it("passes back the result of user input when confirmed", function () { var value = { someKey: 42 }; dialogService.getUserInput({}, value); - mockOverlayService.createOverlay.mostRecentCall.args[1].confirm(); + mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm(); expect(mockDeferred.reject).not.toHaveBeenCalled(); expect(mockDeferred.resolve).toHaveBeenCalledWith(value); }); @@ -109,7 +109,7 @@ define( it("can show multiple dialogs if prior ones are dismissed", function () { dialogService.getUserInput({}, {}); expect(mockLog.warn).not.toHaveBeenCalled(); - mockOverlayService.createOverlay.mostRecentCall.args[1].confirm(); + mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm(); dialogService.getUserInput({}, {}); expect(mockLog.warn).not.toHaveBeenCalled(); expect(mockDeferred.reject).not.toHaveBeenCalled(); @@ -148,13 +148,13 @@ define( it("destroys the event listener when the dialog is cancelled", function () { dialogService.getUserInput({}, {}); - mockOverlayService.createOverlay.mostRecentCall.args[1].cancel(); + mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel(); expect(mockBody.off).toHaveBeenCalledWith("keydown", jasmine.any(Function)); }); it("cancels the dialog when an escape keydown event is triggered", function () { dialogService.getUserInput({}, {}); - mockBody.on.mostRecentCall.args[1]({ + mockBody.on.calls.mostRecent().args[1]({ keyCode: 27 }); expect(mockDeferred.reject).toHaveBeenCalled(); @@ -163,7 +163,7 @@ define( it("ignores non escape keydown events", function () { dialogService.getUserInput({}, {}); - mockBody.on.mostRecentCall.args[1]({ + mockBody.on.calls.mostRecent().args[1]({ keyCode: 13 }); expect(mockDeferred.reject).not.toHaveBeenCalled(); @@ -197,7 +197,7 @@ define( "overlay", ["dismiss"] ); - mockOverlayService.createOverlay.andReturn(secondMockOverlay); + mockOverlayService.createOverlay.and.returnValue(secondMockOverlay); secondDialogHandle = dialogService.showBlockingMessage(dialogModel); //Dismiss the first dialog. It should only dismiss if it diff --git a/platform/commonUI/dialog/test/OverlayServiceSpec.js b/platform/commonUI/dialog/test/OverlayServiceSpec.js index 958faefeb0..c699fb2a10 100644 --- a/platform/commonUI/dialog/test/OverlayServiceSpec.js +++ b/platform/commonUI/dialog/test/OverlayServiceSpec.js @@ -46,10 +46,10 @@ define( mockElement = jasmine.createSpyObj("element", ["remove"]); mockScope = jasmine.createSpyObj("scope", ["$destroy"]); - mockDocument.find.andReturn(mockBody); - mockCompile.andReturn(mockTemplate); - mockRootScope.$new.andReturn(mockScope); - mockTemplate.andReturn(mockElement); + mockDocument.find.and.returnValue(mockBody); + mockCompile.and.returnValue(mockTemplate); + mockRootScope.$new.and.returnValue(mockScope); + mockTemplate.and.returnValue(mockElement); overlayService = new OverlayService( mockDocument, @@ -61,7 +61,7 @@ define( it("prepends an mct-include to create overlays", function () { overlayService.createOverlay("test", {}); expect(mockCompile).toHaveBeenCalled(); - expect(mockCompile.mostRecentCall.args[0].indexOf("mct-include")) + expect(mockCompile.calls.mostRecent().args[0].indexOf("mct-include")) .not.toEqual(-1); }); diff --git a/platform/commonUI/edit/test/actions/CancelActionSpec.js b/platform/commonUI/edit/test/actions/CancelActionSpec.js index c75d747290..98a3ec28ad 100644 --- a/platform/commonUI/edit/test/actions/CancelActionSpec.js +++ b/platform/commonUI/edit/test/actions/CancelActionSpec.js @@ -49,7 +49,7 @@ define( "getModel" ] ); - mockDomainObject.getModel.andReturn({}); + mockDomainObject.getModel.and.returnValue({}); mockParentObject = jasmine.createSpyObj( "parentObject", @@ -57,7 +57,7 @@ define( "getCapability" ] ); - mockParentObject.getCapability.andCallFake(function (name) { + mockParentObject.getCapability.and.callFake(function (name) { return parentCapabilities[name]; }); @@ -77,14 +77,14 @@ define( "getOriginal" ] ); - capabilities.location.getOriginal.andReturn(mockPromise(mockDomainObject)); + capabilities.location.getOriginal.and.returnValue(mockPromise(mockDomainObject)); capabilities.context = jasmine.createSpyObj( "contextCapability", [ "getParent" ] ); - capabilities.context.getParent.andReturn(mockParentObject); + capabilities.context.getParent.and.returnValue(mockParentObject); parentCapabilities.action = jasmine.createSpyObj( "actionCapability", @@ -97,37 +97,37 @@ define( domainObject: mockDomainObject }; - mockDomainObject.getCapability.andCallFake(function (name) { + mockDomainObject.getCapability.and.callFake(function (name) { return capabilities[name]; }); - mockDomainObject.hasCapability.andCallFake(function (name) { + mockDomainObject.hasCapability.and.callFake(function (name) { return !!capabilities[name]; }); - capabilities.editor.finish.andReturn(mockPromise(true)); + capabilities.editor.finish.and.returnValue(mockPromise(true)); action = new CancelAction(actionContext); }); it("only applies to domain object that is being edited", function () { - capabilities.editor.isEditContextRoot.andReturn(true); + capabilities.editor.isEditContextRoot.and.returnValue(true); expect(CancelAction.appliesTo(actionContext)).toBeTruthy(); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - capabilities.editor.isEditContextRoot.andReturn(false); + capabilities.editor.isEditContextRoot.and.returnValue(false); expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); - mockDomainObject.hasCapability.andReturn(false); + mockDomainObject.hasCapability.and.returnValue(false); expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); }); it("invokes the editor capability's cancel functionality when" + " performed", function () { - mockDomainObject.getModel.andReturn({persisted: 1}); + mockDomainObject.getModel.and.returnValue({persisted: 1}); //Return true from navigate action - capabilities.action.perform.andReturn(mockPromise(true)); + capabilities.action.perform.and.returnValue(mockPromise(true)); action.perform(); // Should have called finish @@ -138,15 +138,15 @@ define( }); it("navigates to object if existing using navigate action", function () { - mockDomainObject.getModel.andReturn({persisted: 1}); + mockDomainObject.getModel.and.returnValue({persisted: 1}); //Return true from navigate action - capabilities.action.perform.andReturn(mockPromise(true)); + capabilities.action.perform.and.returnValue(mockPromise(true)); action.perform(); expect(capabilities.action.perform).toHaveBeenCalledWith("navigate"); }); it("navigates to parent if new using navigate action", function () { - mockDomainObject.getModel.andReturn({persisted: undefined}); + mockDomainObject.getModel.and.returnValue({persisted: undefined}); action.perform(); expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate"); }); diff --git a/platform/commonUI/edit/test/actions/EditActionSpec.js b/platform/commonUI/edit/test/actions/EditActionSpec.js index 69bf976496..1dbbbf1432 100644 --- a/platform/commonUI/edit/test/actions/EditActionSpec.js +++ b/platform/commonUI/edit/test/actions/EditActionSpec.js @@ -66,11 +66,11 @@ define( editor: mockEditor }; - mockDomainObject.getCapability.andCallFake(function (name) { + mockDomainObject.getCapability.and.callFake(function (name) { return capabilities[name]; }); - mockDomainObject.hasCapability.andReturn(true); - mockType.hasFeature.andReturn(true); + mockDomainObject.hasCapability.and.returnValue(true); + mockType.hasFeature.and.returnValue(true); actionContext = { domainObject: mockDomainObject }; @@ -92,9 +92,9 @@ define( }); it("is only applicable to objects not already in edit mode", function () { - mockEditor.isEditContextRoot.andReturn(false); + mockEditor.isEditContextRoot.and.returnValue(false); expect(EditAction.appliesTo(actionContext)).toBe(true); - mockEditor.isEditContextRoot.andReturn(true); + mockEditor.isEditContextRoot.and.returnValue(true); expect(EditAction.appliesTo(actionContext)).toBe(false); }); diff --git a/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js index 994104951c..6e2aba90a8 100644 --- a/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js +++ b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js @@ -71,14 +71,14 @@ define( mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]); mockEditAction = jasmine.createSpyObj("editAction", ["perform"]); - mockDomainObject.getId.andReturn("test"); - mockDomainObject.getCapability.andReturn(mockContext); - mockContext.getParent.andReturn(mockParent); - mockType.hasFeature.andReturn(true); - mockType.getKey.andReturn("layout"); - mockComposition.invoke.andReturn(mockPromise(true)); - mockComposition.add.andReturn(mockPromise(true)); - mockActionCapability.getActions.andReturn([]); + mockDomainObject.getId.and.returnValue("test"); + mockDomainObject.getCapability.and.returnValue(mockContext); + mockContext.getParent.and.returnValue(mockParent); + mockType.hasFeature.and.returnValue(true); + mockType.getKey.and.returnValue("layout"); + mockComposition.invoke.and.returnValue(mockPromise(true)); + mockComposition.add.and.returnValue(mockPromise(true)); + mockActionCapability.getActions.and.returnValue([]); capabilities = { composition: mockComposition, @@ -105,14 +105,14 @@ define( }); it("enables edit mode for objects that have an edit action", function () { - mockActionCapability.getActions.andReturn([mockEditAction]); + mockActionCapability.getActions.and.returnValue([mockEditAction]); action.perform(); expect(mockEditAction.perform).toHaveBeenCalled(); }); it("Does not enable edit mode for objects that do not have an" + " edit action", function () { - mockActionCapability.getActions.andReturn([]); + mockActionCapability.getActions.and.returnValue([]); action.perform(); expect(mockEditAction.perform).not.toHaveBeenCalled(); expect(mockComposition.add) diff --git a/platform/commonUI/edit/test/actions/PropertiesActionSpec.js b/platform/commonUI/edit/test/actions/PropertiesActionSpec.js index ae1dc6b1b3..81c36b8d2c 100644 --- a/platform/commonUI/edit/test/actions/PropertiesActionSpec.js +++ b/platform/commonUI/edit/test/actions/PropertiesActionSpec.js @@ -71,8 +71,8 @@ define( } }; - capabilities.type.hasFeature.andReturn(true); - capabilities.mutation.andReturn(true); + capabilities.type.hasFeature.and.returnValue(true); + capabilities.mutation.and.returnValue(true); action = new PropertiesAction(dialogService, context); }); @@ -80,7 +80,7 @@ define( it("mutates an object when performed", function () { action.perform(); expect(capabilities.mutation).toHaveBeenCalled(); - capabilities.mutation.mostRecentCall.args[0]({}); + capabilities.mutation.calls.mostRecent().args[0]({}); }); it("does not muate object upon cancel", function () { diff --git a/platform/commonUI/edit/test/actions/RemoveActionSpec.js b/platform/commonUI/edit/test/actions/RemoveActionSpec.js index 7156ab708a..f9b5089d74 100644 --- a/platform/commonUI/edit/test/actions/RemoveActionSpec.js +++ b/platform/commonUI/edit/test/actions/RemoveActionSpec.js @@ -95,13 +95,13 @@ define( "removeListener" ] ); - mockNavigationService.getNavigation.andReturn(mockDomainObject); + mockNavigationService.getNavigation.and.returnValue(mockDomainObject); - mockDomainObject.getId.andReturn("test"); - mockDomainObject.getCapability.andReturn(mockContext); - mockContext.getParent.andReturn(mockParent); - mockType.hasFeature.andReturn(true); + mockDomainObject.getId.and.returnValue("test"); + mockDomainObject.getCapability.and.returnValue(mockContext); + mockContext.getParent.and.returnValue(mockParent); + mockType.hasFeature.and.returnValue(true); capabilities = { mutation: mockMutation, @@ -119,7 +119,7 @@ define( it("only applies to objects with parents", function () { expect(RemoveAction.appliesTo(actionContext)).toBeTruthy(); - mockContext.getParent.andReturn(undefined); + mockContext.getParent.and.returnValue(undefined); expect(RemoveAction.appliesTo(actionContext)).toBeFalsy(); @@ -136,7 +136,7 @@ define( it("changes composition from its mutation function", function () { var mutator, result; action.perform(); - mutator = mockMutation.invoke.mostRecentCall.args[0]; + mutator = mockMutation.invoke.calls.mostRecent().args[0]; result = mutator(model); // Should not have cancelled the mutation @@ -153,22 +153,22 @@ define( it("removes parent of object currently navigated to", function () { // Navigates to child object - mockNavigationService.getNavigation.andReturn(mockChildObject); + mockNavigationService.getNavigation.and.returnValue(mockChildObject); // Test is id of object being removed // Child object has different id - mockDomainObject.getId.andReturn("test"); - mockChildObject.getId.andReturn("not test"); + mockDomainObject.getId.and.returnValue("test"); + mockChildObject.getId.and.returnValue("not test"); // Sets context for the child and domainObject - mockDomainObject.getCapability.andReturn(mockContext); - mockChildObject.getCapability.andReturn(mockChildContext); + mockDomainObject.getCapability.and.returnValue(mockContext); + mockChildObject.getCapability.and.returnValue(mockChildContext); // Parents of child and domainObject are set - mockContext.getParent.andReturn(mockParent); - mockChildContext.getParent.andReturn(mockDomainObject); + mockContext.getParent.and.returnValue(mockParent); + mockChildContext.getParent.and.returnValue(mockDomainObject); - mockType.hasFeature.andReturn(true); + mockType.hasFeature.and.returnValue(true); action.perform(); @@ -178,25 +178,25 @@ define( it("checks if removing object not in ascendent path (reaches ROOT)", function () { // Navigates to grandchild of ROOT - mockNavigationService.getNavigation.andReturn(mockGrandchildObject); + mockNavigationService.getNavigation.and.returnValue(mockGrandchildObject); // domainObject (grandparent) is set as ROOT, child and grandchild // are set objects not being removed - mockDomainObject.getId.andReturn("test 1"); - mockRootObject.getId.andReturn("ROOT"); - mockChildObject.getId.andReturn("not test 2"); - mockGrandchildObject.getId.andReturn("not test 3"); + mockDomainObject.getId.and.returnValue("test 1"); + mockRootObject.getId.and.returnValue("ROOT"); + mockChildObject.getId.and.returnValue("not test 2"); + mockGrandchildObject.getId.and.returnValue("not test 3"); // Sets context for the grandchild, child, and domainObject - mockRootObject.getCapability.andReturn(mockRootContext); - mockChildObject.getCapability.andReturn(mockChildContext); - mockGrandchildObject.getCapability.andReturn(mockGrandchildContext); + mockRootObject.getCapability.and.returnValue(mockRootContext); + mockChildObject.getCapability.and.returnValue(mockChildContext); + mockGrandchildObject.getCapability.and.returnValue(mockGrandchildContext); // Parents of grandchild and child are set - mockChildContext.getParent.andReturn(mockRootObject); - mockGrandchildContext.getParent.andReturn(mockChildObject); + mockChildContext.getParent.and.returnValue(mockRootObject); + mockGrandchildContext.getParent.and.returnValue(mockChildObject); - mockType.hasFeature.andReturn(true); + mockType.hasFeature.and.returnValue(true); action.perform(); diff --git a/platform/commonUI/edit/test/actions/SaveActionSpec.js b/platform/commonUI/edit/test/actions/SaveActionSpec.js index 9183aff47f..a8b282bd3e 100644 --- a/platform/commonUI/edit/test/actions/SaveActionSpec.js +++ b/platform/commonUI/edit/test/actions/SaveActionSpec.js @@ -19,7 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -/*global describe,it,expect,beforeEach,jasmine,waitsFor,runs*/ +/*global describe,it,expect,beforeEach,jasmine*/ define( ["../../src/actions/SaveAction"], @@ -81,13 +81,13 @@ define( ["info", "error"] ); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andCallFake(function (capability) { + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.callFake(function (capability) { return capabilities[capability]; }); - mockDomainObject.getModel.andReturn({persisted: 0}); - mockEditorCapability.save.andReturn(mockPromise(true)); - mockEditorCapability.isEditContextRoot.andReturn(true); + mockDomainObject.getModel.and.returnValue({persisted: 0}); + mockEditorCapability.save.and.returnValue(mockPromise(true)); + mockEditorCapability.isEditContextRoot.and.returnValue(true); action = new SaveAction(mockDialogService, mockNotificationService, actionContext); }); @@ -96,14 +96,14 @@ define( expect(SaveAction.appliesTo(actionContext)).toBe(true); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - mockDomainObject.hasCapability.andReturn(false); - mockDomainObject.getCapability.andReturn(undefined); + mockDomainObject.hasCapability.and.returnValue(false); + mockDomainObject.getCapability.and.returnValue(undefined); expect(SaveAction.appliesTo(actionContext)).toBe(false); }); it("only applies to domain object that has already been persisted", function () { - mockDomainObject.getModel.andReturn({persisted: undefined}); + mockDomainObject.getModel.and.returnValue({persisted: undefined}); expect(SaveAction.appliesTo(actionContext)).toBe(false); }); @@ -118,11 +118,11 @@ define( beforeEach(function () { mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]); - mockDialogService.showBlockingMessage.andReturn(mockDialogHandle); + mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle); }); it("shows a dialog while saving", function () { - mockEditorCapability.save.andReturn(new Promise(function () { + mockEditorCapability.save.and.returnValue(new Promise(function () { })); action.perform(); expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); @@ -137,12 +137,8 @@ define( it("notifies if saving succeeded", function () { var mockCallback = jasmine.createSpy("callback"); - mockEditorCapability.save.andReturn(Promise.resolve("success")); - action.perform().then(mockCallback); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); - runs(function () { + mockEditorCapability.save.and.returnValue(Promise.resolve()); + return action.perform().then(mockCallback).then(function () { expect(mockNotificationService.info).toHaveBeenCalled(); expect(mockNotificationService.error).not.toHaveBeenCalled(); }); @@ -150,12 +146,8 @@ define( it("notifies if saving failed", function () { var mockCallback = jasmine.createSpy("callback"); - mockEditorCapability.save.andReturn(Promise.reject("some failure reason")); - action.perform().then(mockCallback); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); - runs(function () { + mockEditorCapability.save.and.returnValue(Promise.reject("some failure reason")); + return action.perform().then(mockCallback).then(function () { expect(mockNotificationService.error).toHaveBeenCalled(); expect(mockNotificationService.info).not.toHaveBeenCalled(); }); diff --git a/platform/commonUI/edit/test/actions/SaveAndStopEditingActionSpec.js b/platform/commonUI/edit/test/actions/SaveAndStopEditingActionSpec.js index 828a5c4565..426ad6827e 100644 --- a/platform/commonUI/edit/test/actions/SaveAndStopEditingActionSpec.js +++ b/platform/commonUI/edit/test/actions/SaveAndStopEditingActionSpec.js @@ -86,13 +86,13 @@ define( ["info", "error"] ); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andCallFake(function (capability) { + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.callFake(function (capability) { return capabilities[capability]; }); - mockDomainObject.getModel.andReturn({ persisted: 0 }); - mockEditorCapability.save.andReturn(mockPromise(true)); - mockEditorCapability.isEditContextRoot.andReturn(true); + mockDomainObject.getModel.and.returnValue({ persisted: 0 }); + mockEditorCapability.save.and.returnValue(mockPromise(true)); + mockEditorCapability.isEditContextRoot.and.returnValue(true); action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext); }); @@ -102,18 +102,18 @@ define( expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - mockDomainObject.hasCapability.andReturn(false); - mockDomainObject.getCapability.andReturn(undefined); + mockDomainObject.hasCapability.and.returnValue(false); + mockDomainObject.getCapability.and.returnValue(undefined); expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false); }); it("only applies to domain object that has already been persisted", function () { - mockDomainObject.getModel.andReturn({ persisted: undefined }); + mockDomainObject.getModel.and.returnValue({ persisted: undefined }); expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false); }); it("does not close the editor before completing the save", function () { - mockEditorCapability.save.andReturn(new Promise(function () { + mockEditorCapability.save.and.returnValue(new Promise(function () { })); action.perform(); expect(mockEditorCapability.save).toHaveBeenCalled(); diff --git a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js b/platform/commonUI/edit/test/actions/SaveAsActionSpec.js index 4eeaba866e..73d391cb83 100644 --- a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js +++ b/platform/commonUI/edit/test/actions/SaveAsActionSpec.js @@ -19,7 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -/*global describe,it,expect,beforeEach,jasmine,runs,waitsFor,spyOn*/ +/*global describe,it,expect,beforeEach,jasmine,spyOn*/ define( ["../../src/actions/SaveAsAction"], @@ -63,12 +63,12 @@ define( "getId" ] ); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andCallFake(function (capability) { + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.callFake(function (capability) { return capabilities[capability]; }); - mockDomainObject.getModel.andReturn({location: 'a', persisted: undefined}); - mockDomainObject.getId.andReturn(0); + mockDomainObject.getModel.and.returnValue({location: 'a', persisted: undefined}); + mockDomainObject.getId.and.returnValue(0); mockClonedObject = jasmine.createSpyObj( "clonedObject", @@ -76,7 +76,7 @@ define( "getId" ] ); - mockClonedObject.getId.andReturn(1); + mockClonedObject.getId.and.returnValue(1); mockParent = jasmine.createSpyObj( "parentObject", @@ -91,9 +91,9 @@ define( "editor", ["save", "finish", "isEditContextRoot"] ); - mockEditorCapability.save.andReturn(mockPromise(true)); - mockEditorCapability.finish.andReturn(mockPromise(true)); - mockEditorCapability.isEditContextRoot.andReturn(true); + mockEditorCapability.save.and.returnValue(mockPromise(true)); + mockEditorCapability.finish.and.returnValue(mockPromise(true)); + mockEditorCapability.isEditContextRoot.and.returnValue(true); capabilities.editor = mockEditorCapability; mockActionCapability = jasmine.createSpyObj( @@ -106,7 +106,7 @@ define( "objectService", ["getObjects"] ); - mockObjectService.getObjects.andReturn(mockPromise({'a': mockParent})); + mockObjectService.getObjects.and.returnValue(mockPromise({'a': mockParent})); mockDialogService = jasmine.createSpyObj( "dialogService", @@ -115,7 +115,7 @@ define( "showBlockingMessage" ] ); - mockDialogService.getUserInput.andReturn(mockPromise(undefined)); + mockDialogService.getUserInput.and.returnValue(mockPromise(undefined)); mockCopyService = jasmine.createSpyObj( "copyService", @@ -123,7 +123,7 @@ define( "perform" ] ); - mockCopyService.perform.andReturn(mockPromise(mockClonedObject)); + mockCopyService.perform.and.returnValue(mockPromise(mockClonedObject)); mockNotificationService = jasmine.createSpyObj( "notificationService", @@ -146,10 +146,10 @@ define( actionContext); spyOn(action, "getObjectService"); - action.getObjectService.andReturn(mockObjectService); + action.getObjectService.and.returnValue(mockObjectService); spyOn(action, "createWizard"); - action.createWizard.andReturn({ + action.createWizard.and.returnValue({ getFormStructure: noop, getInitialFormValue: noop, populateObjectFromInput: function () { @@ -163,8 +163,8 @@ define( expect(SaveAsAction.appliesTo(actionContext)).toBe(true); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - mockDomainObject.hasCapability.andReturn(false); - mockDomainObject.getCapability.andReturn(undefined); + mockDomainObject.hasCapability.and.returnValue(false); + mockDomainObject.getCapability.and.returnValue(undefined); expect(SaveAsAction.appliesTo(actionContext)).toBe(false); }); @@ -173,35 +173,27 @@ define( expect(SaveAsAction.appliesTo(actionContext)).toBe(true); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - mockDomainObject.getModel.andReturn({persisted: 0}); + mockDomainObject.getModel.and.returnValue({persisted: 0}); expect(SaveAsAction.appliesTo(actionContext)).toBe(false); }); it("uses the editor capability to save the object", function () { - mockEditorCapability.save.andReturn(new Promise(function () {})); - runs(function () { - action.perform(); - }); - waitsFor(function () { - return mockEditorCapability.save.calls.length > 0; - }, "perform() should call EditorCapability.save"); - runs(function () { - expect(mockEditorCapability.finish).not.toHaveBeenCalled(); + mockEditorCapability.save.and.returnValue(Promise.resolve()); + + return action.perform().then(function () { + expect(mockEditorCapability.save).toHaveBeenCalled(); }); }); it("uses the editor capability to finish editing the object", function () { - runs(function () { - action.perform(); + return action.perform().then(function () { + expect(mockEditorCapability.finish.calls.count()).toBeGreaterThan(0); }); - waitsFor(function () { - return mockEditorCapability.finish.calls.length > 0; - }, "perform() should call EditorCapability.finish"); }); it("returns to browse after save", function () { spyOn(action, "save"); - action.save.andReturn(mockPromise(mockDomainObject)); + action.save.and.returnValue(mockPromise(mockDomainObject)); action.perform(); expect(mockActionCapability.perform).toHaveBeenCalledWith( "navigate" @@ -218,48 +210,33 @@ define( beforeEach(function () { mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]); - mockDialogService.showBlockingMessage.andReturn(mockDialogHandle); + mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle); }); it("shows a blocking dialog indicating that saving is in progress", function () { - mockEditorCapability.save.andReturn(new Promise(function () {})); + mockEditorCapability.save.and.returnValue(new Promise(function () {})); action.perform(); expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); expect(mockDialogHandle.dismiss).not.toHaveBeenCalled(); }); it("hides the blocking dialog after saving finishes", function () { - var mockCallback = jasmine.createSpy(); - action.perform().then(mockCallback); - expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); - runs(function () { + return action.perform().then(function () { + expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); expect(mockDialogHandle.dismiss).toHaveBeenCalled(); }); }); it("notifies if saving succeeded", function () { - var mockCallback = jasmine.createSpy(); - action.perform().then(mockCallback); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); - runs(function () { + return action.perform().then(function () { expect(mockNotificationService.info).toHaveBeenCalled(); expect(mockNotificationService.error).not.toHaveBeenCalled(); }); }); it("notifies if saving failed", function () { - mockCopyService.perform.andReturn(Promise.reject("some failure reason")); - var mockCallback = jasmine.createSpy(); - action.perform().then(mockCallback); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); - runs(function () { + mockCopyService.perform.and.returnValue(Promise.reject("some failure reason")); + action.perform().then(function () { expect(mockNotificationService.error).toHaveBeenCalled(); expect(mockNotificationService.info).not.toHaveBeenCalled(); }); diff --git a/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js index 63720b6473..b469284121 100644 --- a/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js +++ b/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js @@ -60,8 +60,8 @@ define( "cancel" ] ); - mockTransactionService.commit.andReturn(fastPromise()); - mockTransactionService.cancel.andReturn(fastPromise()); + mockTransactionService.commit.and.returnValue(fastPromise()); + mockTransactionService.cancel.and.returnValue(fastPromise()); mockTransactionService.isActive = jasmine.createSpy('isActive'); mockStatusCapability = jasmine.createSpyObj( @@ -76,23 +76,23 @@ define( "contextCapability", ["getParent"] ); - mockContextCapability.getParent.andReturn(mockParentObject); + mockContextCapability.getParent.and.returnValue(mockParentObject); capabilities = { context: mockContextCapability, status: mockStatusCapability }; - mockDomainObject.hasCapability.andCallFake(function (name) { + mockDomainObject.hasCapability.and.callFake(function (name) { return capabilities[name] !== undefined; }); - mockDomainObject.getCapability.andCallFake(function (name) { + mockDomainObject.getCapability.and.callFake(function (name) { return capabilities[name]; }); - mockParentObject.getCapability.andReturn(mockParentStatus); - mockParentObject.hasCapability.andReturn(false); + mockParentObject.getCapability.and.returnValue(mockParentStatus); + mockParentObject.hasCapability.and.returnValue(false); capability = new EditorCapability( mockTransactionService, @@ -112,18 +112,18 @@ define( it("uses editing status to determine editing context root", function () { capability.edit(); - mockStatusCapability.get.andReturn(false); + mockStatusCapability.get.and.returnValue(false); expect(capability.isEditContextRoot()).toBe(false); - mockStatusCapability.get.andReturn(true); + mockStatusCapability.get.and.returnValue(true); expect(capability.isEditContextRoot()).toBe(true); }); it("inEditingContext returns true if parent object is being" + " edited", function () { - mockStatusCapability.get.andReturn(false); - mockParentStatus.get.andReturn(false); + mockStatusCapability.get.and.returnValue(false); + mockParentStatus.get.and.returnValue(false); expect(capability.inEditContext()).toBe(false); - mockParentStatus.get.andReturn(true); + mockParentStatus.get.and.returnValue(true); expect(capability.inEditContext()).toBe(true); }); @@ -142,7 +142,7 @@ define( describe("finish", function () { beforeEach(function () { - mockTransactionService.isActive.andReturn(true); + mockTransactionService.isActive.and.returnValue(true); capability.edit(); capability.finish(); }); @@ -156,7 +156,7 @@ define( describe("finish", function () { beforeEach(function () { - mockTransactionService.isActive.andReturn(false); + mockTransactionService.isActive.and.returnValue(false); capability.edit(); }); @@ -175,15 +175,15 @@ define( var model = {}; beforeEach(function () { - mockDomainObject.getModel.andReturn(model); + mockDomainObject.getModel.and.returnValue(model); capability.edit(); capability.finish(); }); it("returns true if the object has been modified since it" + " was last persisted", function () { - mockTransactionService.size.andReturn(0); + mockTransactionService.size.and.returnValue(0); expect(capability.dirty()).toBe(false); - mockTransactionService.size.andReturn(1); + mockTransactionService.size.and.returnValue(1); expect(capability.dirty()).toBe(true); }); }); diff --git a/platform/commonUI/edit/test/capabilities/TransactionCapabilityDecoratorSpec.js b/platform/commonUI/edit/test/capabilities/TransactionCapabilityDecoratorSpec.js index 7e3d4f957f..07bc867e41 100644 --- a/platform/commonUI/edit/test/capabilities/TransactionCapabilityDecoratorSpec.js +++ b/platform/commonUI/edit/test/capabilities/TransactionCapabilityDecoratorSpec.js @@ -37,7 +37,7 @@ define( mockQ = {}; mockTransactionService = {}; mockCapabilityService = jasmine.createSpyObj("capabilityService", ["getCapabilities"]); - mockCapabilityService.getCapabilities.andReturn({ + mockCapabilityService.getCapabilities.and.returnValue({ persistence: function () {} }); diff --git a/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js index f0da63a8b1..3d038d805d 100644 --- a/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js +++ b/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js @@ -47,7 +47,7 @@ define( testId = "test-id"; mockQ = jasmine.createSpyObj("$q", ["when"]); - mockQ.when.andCallFake(function (val) { + mockQ.when.and.callFake(function (val) { return fastPromise(val); }); mockTransactionManager = jasmine.createSpyObj( @@ -58,15 +58,15 @@ define( "persistenceCapability", ["persist", "refresh", "getSpace"] ); - mockPersistence.persist.andReturn(fastPromise()); - mockPersistence.refresh.andReturn(fastPromise()); + mockPersistence.persist.and.returnValue(fastPromise()); + mockPersistence.refresh.and.returnValue(fastPromise()); mockDomainObject = jasmine.createSpyObj( "domainObject", ["getModel", "getId"] ); - mockDomainObject.getModel.andReturn({persisted: 1}); - mockDomainObject.getId.andReturn(testId); + mockDomainObject.getModel.and.returnValue({persisted: 1}); + mockDomainObject.getId.and.returnValue(testId); capability = new TransactionalPersistenceCapability( mockQ, @@ -78,24 +78,24 @@ define( it("if no transaction is active, passes through to persistence" + " provider", function () { - mockTransactionManager.isActive.andReturn(false); + mockTransactionManager.isActive.and.returnValue(false); capability.persist(); expect(mockPersistence.persist).toHaveBeenCalled(); }); it("if transaction is active, persist and cancel calls are" + " queued", function () { - mockTransactionManager.isActive.andReturn(true); + mockTransactionManager.isActive.and.returnValue(true); capability.persist(); expect(mockTransactionManager.addToTransaction).toHaveBeenCalled(); - mockTransactionManager.addToTransaction.mostRecentCall.args[1](); + mockTransactionManager.addToTransaction.calls.mostRecent().args[1](); expect(mockPersistence.persist).toHaveBeenCalled(); - mockTransactionManager.addToTransaction.mostRecentCall.args[2](); + mockTransactionManager.addToTransaction.calls.mostRecent().args[2](); expect(mockPersistence.refresh).toHaveBeenCalled(); }); it("wraps getSpace", function () { - mockPersistence.getSpace.andReturn('foo'); + mockPersistence.getSpace.and.returnValue('foo'); expect(capability.getSpace()).toEqual('foo'); }); diff --git a/platform/commonUI/edit/test/controllers/EditActionControllerSpec.js b/platform/commonUI/edit/test/controllers/EditActionControllerSpec.js index 4f454d8bf1..12183efdb3 100644 --- a/platform/commonUI/edit/test/controllers/EditActionControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/EditActionControllerSpec.js @@ -38,7 +38,7 @@ define( jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"]) ]; mockedSaveActions.forEach(function (action) { - action.getMetadata.andReturn(mockSaveActionMetadata); + action.getMetadata.and.returnValue(mockSaveActionMetadata); }); return mockedSaveActions; } else if (actionContext.category === "conclude-editing") { @@ -54,14 +54,14 @@ define( beforeEach(function () { mockActions = jasmine.createSpyObj("action", ["getActions"]); - mockActions.getActions.andCallFake(fakeGetActions); + mockActions.getActions.and.callFake(fakeGetActions); mockScope = jasmine.createSpyObj("$scope", ["$watch"]); mockScope.action = mockActions; controller = new EditActionController(mockScope); }); function makeControllerUpdateActions() { - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); } it("watches scope that may change applicable actions", function () { diff --git a/platform/commonUI/edit/test/controllers/EditObjectControllerSpec.js b/platform/commonUI/edit/test/controllers/EditObjectControllerSpec.js index 4ad82456f8..d3dd66459d 100644 --- a/platform/commonUI/edit/test/controllers/EditObjectControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/EditObjectControllerSpec.js @@ -61,17 +61,17 @@ define( mockLocation = jasmine.createSpyObj('$location', ["search"] ); - mockLocation.search.andReturn({"view": "fixed"}); + mockLocation.search.and.returnValue({"view": "fixed"}); mockNavigationService = jasmine.createSpyObj('navigationService', ["checkBeforeNavigation"] ); removeCheck = jasmine.createSpy('removeCheck'); - mockNavigationService.checkBeforeNavigation.andReturn(removeCheck); + mockNavigationService.checkBeforeNavigation.and.returnValue(removeCheck); - mockObject.getId.andReturn("test"); - mockObject.getModel.andReturn({ name: "Test object" }); - mockObject.getCapability.andCallFake(function (key) { + mockObject.getId.and.returnValue("test"); + mockObject.getModel.and.returnValue({ name: "Test object" }); + mockObject.getCapability.and.callFake(function (key) { return mockCapabilities[key]; }); @@ -81,10 +81,10 @@ define( { key: 'xyz' } ]; - mockObject.useCapability.andCallFake(function (c) { + mockObject.useCapability.and.callFake(function (c) { return (c === 'view') && testViews; }); - mockLocation.search.andReturn({ view: 'def' }); + mockLocation.search.and.returnValue({ view: 'def' }); mockScope.domainObject = mockObject; @@ -99,17 +99,17 @@ define( expect(mockNavigationService.checkBeforeNavigation) .toHaveBeenCalledWith(jasmine.any(Function)); - var checkFn = mockNavigationService.checkBeforeNavigation.mostRecentCall.args[0]; + var checkFn = mockNavigationService.checkBeforeNavigation.calls.mostRecent().args[0]; - mockEditorCapability.isEditContextRoot.andReturn(false); - mockEditorCapability.dirty.andReturn(false); + mockEditorCapability.isEditContextRoot.and.returnValue(false); + mockEditorCapability.dirty.and.returnValue(false); expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes."); - mockEditorCapability.isEditContextRoot.andReturn(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes."); - mockEditorCapability.dirty.andReturn(true); + mockEditorCapability.dirty.and.returnValue(true); expect(checkFn()) .toBe("Continuing will cause the loss of any unsaved changes."); @@ -119,7 +119,7 @@ define( expect(mockScope.$on) .toHaveBeenCalledWith("$destroy", jasmine.any(Function)); - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); expect(mockEditorCapability.finish).toHaveBeenCalled(); expect(removeCheck).toHaveBeenCalled(); diff --git a/platform/commonUI/edit/test/controllers/EditPanesControllerSpec.js b/platform/commonUI/edit/test/controllers/EditPanesControllerSpec.js index 98f0c7d02c..abb02df272 100644 --- a/platform/commonUI/edit/test/controllers/EditPanesControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/EditPanesControllerSpec.js @@ -41,13 +41,13 @@ define( ['getTrueRoot'] ); - mockDomainObject.getId.andReturn('test-id'); - mockDomainObject.getCapability.andReturn(mockContext); + mockDomainObject.getId.and.returnValue('test-id'); + mockDomainObject.getCapability.and.returnValue(mockContext); // Return a new instance of the root object each time - mockContext.getTrueRoot.andCallFake(function () { + mockContext.getTrueRoot.and.callFake(function () { var mockRoot = jasmine.createSpyObj('root', ['getId']); - mockRoot.getId.andReturn('root-id'); + mockRoot.getId.and.returnValue('root-id'); return mockRoot; }); @@ -63,7 +63,7 @@ define( }); it("exposes the root object found via the object's context capability", function () { - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); // Verify that the correct capability was used expect(mockDomainObject.getCapability) @@ -76,10 +76,10 @@ define( it("preserves the same root instance to avoid excessive refreshing", function () { var firstRoot; // Expose the domain object - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); firstRoot = controller.getRoot(); // Update! - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); // Should still have the same object instance, to avoid // triggering the watch used by the template we're supporting expect(controller.getRoot()).toBe(firstRoot); @@ -90,18 +90,18 @@ define( it("updates the root when it changes", function () { var firstRoot; // Expose the domain object - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); firstRoot = controller.getRoot(); // Change the exposed root - mockContext.getTrueRoot.andCallFake(function () { + mockContext.getTrueRoot.and.callFake(function () { var mockRoot = jasmine.createSpyObj('root', ['getId']); - mockRoot.getId.andReturn('other-root-id'); + mockRoot.getId.and.returnValue('other-root-id'); return mockRoot; }); // Update! - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); // Should still have the same object instance, to avoid // triggering the watch used by the template we're supporting diff --git a/platform/commonUI/edit/test/controllers/ElementsControllerSpec.js b/platform/commonUI/edit/test/controllers/ElementsControllerSpec.js index 2dd8dba2bb..9a46941080 100644 --- a/platform/commonUI/edit/test/controllers/ElementsControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/ElementsControllerSpec.js @@ -63,13 +63,13 @@ define( mockMutationCapability = jasmine.createSpyObj("mutationCapability", [ "listen" ]); - mockMutationCapability.listen.andReturn(mockUnlisten); + mockMutationCapability.listen.and.returnValue(mockUnlisten); mockDomainObject = jasmine.createSpyObj("domainObject", [ "getCapability", "useCapability" ]); - mockDomainObject.useCapability.andReturn(mockCompositionCapability); - mockDomainObject.getCapability.andReturn(mockMutationCapability); + mockDomainObject.useCapability.and.returnValue(mockCompositionCapability); + mockDomainObject.getCapability.and.returnValue(mockMutationCapability); mockScope = jasmine.createSpyObj("$scope", ['$on']); mockSelection = jasmine.createSpyObj("selection", [ @@ -77,7 +77,7 @@ define( 'off', 'get' ]); - mockSelection.get.andReturn([]); + mockSelection.get.and.returnValue([]); mockOpenMCT = { selection: mockSelection }; @@ -88,7 +88,7 @@ define( } }; - spyOn(ElementsController.prototype, 'refreshComposition').andCallThrough(); + spyOn(ElementsController.prototype, 'refreshComposition').and.callThrough(); controller = new ElementsController(mockScope, mockOpenMCT); }); @@ -123,29 +123,29 @@ define( }); it("refreshes composition on selection", function () { - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(ElementsController.prototype.refreshComposition).toHaveBeenCalledWith(mockDomainObject); }); it("listens on mutation and refreshes composition", function () { - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(mockDomainObject.getCapability).toHaveBeenCalledWith('mutation'); expect(mockMutationCapability.listen).toHaveBeenCalled(); - expect(ElementsController.prototype.refreshComposition.calls.length).toBe(1); + expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(1); - mockMutationCapability.listen.mostRecentCall.args[0](mockDomainObject); + mockMutationCapability.listen.calls.mostRecent().args[0](mockDomainObject); - expect(ElementsController.prototype.refreshComposition.calls.length).toBe(2); + expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(2); }); it("cleans up mutation listener when selection changes", function () { - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(mockMutationCapability.listen).toHaveBeenCalled(); - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(mockUnlisten).toHaveBeenCalled(); }); @@ -156,7 +156,7 @@ define( elementProxy: {} } }; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation'); }); @@ -167,13 +167,13 @@ define( firstCompositionCallback, secondCompositionCallback; - spyOn(mockCompositionCapability, "then").andCallThrough(); + spyOn(mockCompositionCapability, "then").and.callThrough(); controller.refreshComposition(mockDomainObject); controller.refreshComposition(mockDomainObject); - firstCompositionCallback = mockCompositionCapability.then.calls[0].args[0]; - secondCompositionCallback = mockCompositionCapability.then.calls[1].args[0]; + firstCompositionCallback = mockCompositionCapability.then.calls.all()[0].args[0]; + secondCompositionCallback = mockCompositionCapability.then.calls.all()[1].args[0]; secondCompositionCallback(secondMockCompositionObjects); firstCompositionCallback(mockCompositionObjects); diff --git a/platform/commonUI/edit/test/creation/AddActionProviderSpec.js b/platform/commonUI/edit/test/creation/AddActionProviderSpec.js index 5ecf8442e9..6d410919d5 100644 --- a/platform/commonUI/edit/test/creation/AddActionProviderSpec.js +++ b/platform/commonUI/edit/test/creation/AddActionProviderSpec.js @@ -51,9 +51,9 @@ define( "hasFeature" ] ); - mockType.hasFeature.andReturn(true); - mockType.getName.andReturn(name); - mockType.getKey.andReturn(name); + mockType.hasFeature.and.returnValue(true); + mockType.getName.and.returnValue(name); + mockType.getKey.and.returnValue(name); return mockType; } @@ -77,7 +77,7 @@ define( mockTypeMap[type.getKey()] = type; }); - mockTypeService.getType.andCallFake(function (key) { + mockTypeService.getType.and.callFake(function (key) { return mockTypeMap[key]; }); diff --git a/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js b/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js index d558732ab6..bc97c73a24 100644 --- a/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js +++ b/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js @@ -49,8 +49,8 @@ define( "hasFeature" ] ); - mockType.hasFeature.andReturn(true); - mockType.getName.andReturn(name); + mockType.hasFeature.and.returnValue(true); + mockType.getName.and.returnValue(name); return mockType; } @@ -74,11 +74,11 @@ define( return mockPolicyMap[type.getName()]; }; - mockPolicyService.allow.andCallFake(function (category, type) { + mockPolicyService.allow.and.callFake(function (category, type) { return category === "creation" && mockCreationPolicy(type) ? true : false; }); - mockTypeService.listTypes.andReturn(mockTypes); + mockTypeService.listTypes.and.returnValue(mockTypes); provider = new CreateActionProvider( mockTypeService, diff --git a/platform/commonUI/edit/test/creation/CreateActionSpec.js b/platform/commonUI/edit/test/creation/CreateActionSpec.js index 0070f686dc..267258dc1d 100644 --- a/platform/commonUI/edit/test/creation/CreateActionSpec.js +++ b/platform/commonUI/edit/test/creation/CreateActionSpec.js @@ -77,10 +77,10 @@ define( "useCapability" ] ); - mockDomainObject.hasCapability.andCallFake(function (name) { + mockDomainObject.hasCapability.and.callFake(function (name) { return !!capabilities[name]; }); - mockDomainObject.getCapability.andCallFake(function (name) { + mockDomainObject.getCapability.and.callFake(function (name) { return capabilities[name]; }); mockSaveAction = jasmine.createSpyObj( @@ -117,14 +117,14 @@ define( mockContext = { domainObject: mockParent }; - mockParent.useCapability.andReturn(mockDomainObject); + mockParent.useCapability.and.returnValue(mockDomainObject); - mockType.getKey.andReturn("test"); - mockType.getCssClass.andReturn("icon-telemetry"); - mockType.getDescription.andReturn("a test type"); - mockType.getName.andReturn("Test"); - mockType.getProperties.andReturn([]); - mockType.getInitialModel.andReturn({}); + mockType.getKey.and.returnValue("test"); + mockType.getCssClass.and.returnValue("icon-telemetry"); + mockType.getDescription.and.returnValue("a test type"); + mockType.getName.and.returnValue("Test"); + mockType.getProperties.and.returnValue([]); + mockType.getInitialModel.and.returnValue({}); action = new CreateAction( mockType, @@ -144,7 +144,7 @@ define( describe("the perform function", function () { var promise = jasmine.createSpyObj("promise", ["then"]); beforeEach(function () { - capabilities.action.getActions.andReturn([mockEditAction]); + capabilities.action.getActions.and.returnValue([mockEditAction]); }); it("uses the instantiation capability when performed", function () { @@ -159,30 +159,30 @@ define( it("uses the save-as action if object does not have an edit action" + " available", function () { - capabilities.action.getActions.andReturn([]); - capabilities.action.perform.andReturn(mockPromise(undefined)); - capabilities.editor.save.andReturn(promise); + capabilities.action.getActions.and.returnValue([]); + capabilities.action.perform.and.returnValue(mockPromise(undefined)); + capabilities.editor.save.and.returnValue(promise); action.perform(); expect(capabilities.action.perform).toHaveBeenCalledWith("save-as"); }); describe("uses to editor capability", function () { beforeEach(function () { - capabilities.action.getActions.andReturn([]); - capabilities.action.perform.andReturn(promise); - capabilities.editor.save.andReturn(promise); + capabilities.action.getActions.and.returnValue([]); + capabilities.action.perform.and.returnValue(promise); + capabilities.editor.save.and.returnValue(promise); }); it("to save the edit if user saves dialog", function () { action.perform(); expect(promise.then).toHaveBeenCalled(); - promise.then.mostRecentCall.args[0](); + promise.then.calls.mostRecent().args[0](); expect(capabilities.editor.save).toHaveBeenCalled(); }); it("to finish the edit if user cancels dialog", function () { action.perform(); - promise.then.mostRecentCall.args[1](); + promise.then.calls.mostRecent().args[1](); expect(capabilities.editor.finish).toHaveBeenCalled(); }); }); diff --git a/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js b/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js index 978a87f8de..de09b0ac35 100644 --- a/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js +++ b/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js @@ -49,10 +49,10 @@ define( it("populates the scope with create actions", function () { mockScope.action = mockActions; - mockActions.getActions.andReturn(["a", "b", "c"]); + mockActions.getActions.and.returnValue(["a", "b", "c"]); // Call the watch - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); // Should have grouped and ungrouped actions in scope now expect(mockScope.createActions.length).toEqual(3); diff --git a/platform/commonUI/edit/test/creation/CreateWizardSpec.js b/platform/commonUI/edit/test/creation/CreateWizardSpec.js index ee0fa04a51..fd424e0471 100644 --- a/platform/commonUI/edit/test/creation/CreateWizardSpec.js +++ b/platform/commonUI/edit/test/creation/CreateWizardSpec.js @@ -41,10 +41,10 @@ define( "property" + name, ["getDefinition", "getValue", "setValue"] ); - mockProperty.getDefinition.andReturn({ + mockProperty.getDefinition.and.returnValue({ control: "textfield" }); - mockProperty.getValue.andReturn(name); + mockProperty.getValue.and.returnValue(name); return mockProperty; } @@ -74,12 +74,12 @@ define( testModel = { someKey: "some value" }; - mockType.getKey.andReturn("test"); - mockType.getCssClass.andReturn("icon-telemetry"); - mockType.getDescription.andReturn("a test type"); - mockType.getName.andReturn("Test"); - mockType.getInitialModel.andReturn(testModel); - mockType.getProperties.andReturn(mockProperties); + mockType.getKey.and.returnValue("test"); + mockType.getCssClass.and.returnValue("icon-telemetry"); + mockType.getDescription.and.returnValue("a test type"); + mockType.getName.and.returnValue("Test"); + mockType.getInitialModel.and.returnValue(testModel); + mockType.getProperties.and.returnValue(mockProperties); mockDomainObject = jasmine.createSpyObj( 'domainObject', @@ -87,9 +87,9 @@ define( ); //Mocking the getCapability('type') call - mockDomainObject.getCapability.andReturn(mockType); - mockDomainObject.useCapability.andReturn(); - mockDomainObject.getModel.andReturn(testModel); + mockDomainObject.getCapability.and.returnValue(mockType); + mockDomainObject.useCapability.and.returnValue(); + mockDomainObject.getModel.and.returnValue(testModel); wizard = new CreateWizard( mockDomainObject, @@ -147,9 +147,11 @@ define( "C": "ValueC" }, compareModel = wizard.createModel(formValue); + //populateObjectFromInput adds a .location attribute that is not added by createModel. + compareModel.location = undefined; wizard.populateObjectFromInput(formValue); expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function)); - expect(mockDomainObject.useCapability.mostRecentCall.args[1]()).toEqual(compareModel); + expect(mockDomainObject.useCapability.calls.mostRecent().args[1]()).toEqual(compareModel); }); it("validates selection types using policy", function () { @@ -168,7 +170,7 @@ define( rows = structure.sections[sections.length - 1].rows, locationRow = rows[rows.length - 1]; - mockDomainObj.getCapability.andReturn(mockOtherType); + mockDomainObj.getCapability.and.returnValue(mockOtherType); locationRow.validate(mockDomainObj); // Should check policy to see if the user-selected location diff --git a/platform/commonUI/edit/test/creation/CreationPolicySpec.js b/platform/commonUI/edit/test/creation/CreationPolicySpec.js index 11ff40f170..a76d89179a 100644 --- a/platform/commonUI/edit/test/creation/CreationPolicySpec.js +++ b/platform/commonUI/edit/test/creation/CreationPolicySpec.js @@ -38,12 +38,12 @@ define( }); it("allows creation of types with the creation feature", function () { - mockType.hasFeature.andReturn(true); + mockType.hasFeature.and.returnValue(true); expect(policy.allow(mockType)).toBeTruthy(); }); it("disallows creation of types without the creation feature", function () { - mockType.hasFeature.andReturn(false); + mockType.hasFeature.and.returnValue(false); expect(policy.allow(mockType)).toBeFalsy(); }); }); diff --git a/platform/commonUI/edit/test/creation/CreationServiceSpec.js b/platform/commonUI/edit/test/creation/CreationServiceSpec.js index 5757f31d1e..3f0139230e 100644 --- a/platform/commonUI/edit/test/creation/CreationServiceSpec.js +++ b/platform/commonUI/edit/test/creation/CreationServiceSpec.js @@ -103,33 +103,33 @@ define( ["persist", "getSpace"] ); - mockParentObject.getCapability.andCallFake(function (key) { + mockParentObject.getCapability.and.callFake(function (key) { return mockCapabilities[key]; }); - mockParentObject.useCapability.andCallFake(function (key, value) { + mockParentObject.useCapability.and.callFake(function (key, value) { return mockCapabilities[key].invoke(value); }); - mockParentObject.getId.andReturn('parentId'); + mockParentObject.getId.and.returnValue('parentId'); - mockNewObject.getId.andReturn('newId'); - mockNewObject.getCapability.andCallFake(function (c) { + mockNewObject.getId.and.returnValue('newId'); + mockNewObject.getCapability.and.callFake(function (c) { return c === 'persistence' ? mockNewPersistenceCapability : undefined; }); mockPersistenceCapability.persist - .andReturn(mockPromise(true)); + .and.returnValue(mockPromise(true)); mockNewPersistenceCapability.persist - .andReturn(mockPromise(true)); + .and.returnValue(mockPromise(true)); - mockMutationCapability.invoke.andReturn(mockPromise(true)); - mockPersistenceCapability.getSpace.andReturn("testSpace"); - mockCompositionCapability.invoke.andReturn( + mockMutationCapability.invoke.and.returnValue(mockPromise(true)); + mockPersistenceCapability.getSpace.and.returnValue("testSpace"); + mockCompositionCapability.invoke.and.returnValue( mockPromise([mockNewObject]) ); - mockCompositionCapability.add.andReturn(mockPromise(true)); - mockCreationCapability.instantiate.andReturn(mockNewObject); - mockCreationCapability.invoke.andCallFake(function (model) { + mockCompositionCapability.add.and.returnValue(mockPromise(true)); + mockCreationCapability.instantiate.and.returnValue(mockNewObject); + mockCreationCapability.invoke.and.callFake(function (model) { return mockCreationCapability.instantiate(model); }); @@ -163,10 +163,10 @@ define( mockCallback = jasmine.createSpy('callback'); // Act as if the object had been created - mockCompositionCapability.add.andCallFake(function (id) { - mockDomainObject.getId.andReturn(id); + mockCompositionCapability.add.and.callFake(function (id) { + mockDomainObject.getId.and.returnValue(id); mockCompositionCapability.invoke - .andReturn(mockPromise([mockDomainObject])); + .and.returnValue(mockPromise([mockDomainObject])); return mockPromise(mockDomainObject); }); @@ -200,7 +200,7 @@ define( // created object - this is an error. var model = { someKey: "some value" }; - mockCompositionCapability.add.andReturn(mockPromise(false)); + mockCompositionCapability.add.and.returnValue(mockPromise(false)); creationService.createObject(model, mockParentObject); diff --git a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js b/platform/commonUI/edit/test/creation/LocatorControllerSpec.js index a960242382..5024323783 100644 --- a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js +++ b/platform/commonUI/edit/test/creation/LocatorControllerSpec.js @@ -64,9 +64,9 @@ define( ["then"] ); - mockDomainObject.getCapability.andReturn(mockContext); - mockContext.getRoot.andReturn(mockRootObject); - mockObjectService.getObjects.andReturn(getObjectsPromise); + mockDomainObject.getCapability.and.returnValue(mockContext); + mockContext.getRoot.and.returnValue(mockRootObject); + mockObjectService.getObjects.and.returnValue(getObjectsPromise); mockScope.ngModel = {}; mockScope.field = "someField"; @@ -76,7 +76,7 @@ define( describe("when context is available", function () { beforeEach(function () { - mockContext.getRoot.andReturn(mockRootObject); + mockContext.getRoot.and.returnValue(mockRootObject); controller = new LocatorController(mockScope, mockTimeout, mockObjectService); }); @@ -96,8 +96,8 @@ define( it("changes its own model on embedded model updates", function () { // Need to pass on selection changes as updates to // the control's value - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.ngModel.someField).toEqual(mockDomainObject); expect(mockScope.rootObject).toEqual(mockRootObject); @@ -109,11 +109,11 @@ define( it("rejects changes which fail validation", function () { mockScope.structure = { validate: jasmine.createSpy('validate') }; - mockScope.structure.validate.andReturn(false); + mockScope.structure.validate.and.returnValue(false); // Pass selection change - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.structure.validate).toHaveBeenCalled(); // Change should have been rejected @@ -126,13 +126,13 @@ define( ['$setValidity'] ); - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.ngModelController.$setValidity) .toHaveBeenCalledWith(jasmine.any(String), true); - mockScope.$watch.mostRecentCall.args[1](undefined); - mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.calls.mostRecent().args[1](undefined); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.ngModelController.$setValidity) .toHaveBeenCalledWith(jasmine.any(String), false); }); @@ -141,27 +141,27 @@ define( var defaultRoot = "DEFAULT_ROOT"; beforeEach(function () { - mockContext.getRoot.andReturn(undefined); - getObjectsPromise.then.andCallFake(function (callback) { + mockContext.getRoot.and.returnValue(undefined); + getObjectsPromise.then.and.callFake(function (callback) { callback({'ROOT': defaultRoot}); }); controller = new LocatorController(mockScope, mockTimeout, mockObjectService); }); it("provides a default context where none is available", function () { - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.rootObject).toBe(defaultRoot); }); it("does not issue redundant requests for the root object", function () { - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); - mockScope.$watch.mostRecentCall.args[1](undefined); - mockTimeout.mostRecentCall.args[0](); - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); - expect(mockObjectService.getObjects.calls.length) + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); + mockScope.$watch.calls.mostRecent().args[1](undefined); + mockTimeout.calls.mostRecent().args[0](); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); + mockTimeout.calls.mostRecent().args[0](); + expect(mockObjectService.getObjects.calls.count()) .toEqual(1); }); diff --git a/platform/commonUI/edit/test/policies/EditActionPolicySpec.js b/platform/commonUI/edit/test/policies/EditActionPolicySpec.js index 9cfbc1e690..2b9174488f 100644 --- a/platform/commonUI/edit/test/policies/EditActionPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditActionPolicySpec.js @@ -58,10 +58,10 @@ define( mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']); mockPropertiesAction = jasmine.createSpyObj('edit', ['getMetadata']); - mockDomainObject.getCapability.andCallFake(function (capability) { + mockDomainObject.getCapability.and.callFake(function (capability) { return capabilities[capability]; }); - mockDomainObject.hasCapability.andCallFake(function (capability) { + mockDomainObject.hasCapability.and.callFake(function (capability) { return !!capabilities[capability]; }); @@ -71,13 +71,13 @@ define( plotView = { key: "plot", editable: false }; testViews = []; - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { // Provide test views, only for the view capability return c === 'view' && testViews; }); - mockEditAction.getMetadata.andReturn({ key: 'edit' }); - mockPropertiesAction.getMetadata.andReturn({ key: 'properties' }); + mockEditAction.getMetadata.and.returnValue({ key: 'edit' }); + mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' }); testContext = { domainObject: mockDomainObject, @@ -111,20 +111,20 @@ define( it("disallows the edit action when object is already being" + " edited", function () { testViews = [editableView]; - mockEditorCapability.isEditContextRoot.andReturn(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); expect(policy.allow(mockEditAction, testContext)).toBe(false); }); it("allows editing of panels in plot view", function () { testViews = [plotView]; - mockTypeCapability.getKey.andReturn('telemetry.panel'); + mockTypeCapability.getKey.and.returnValue('telemetry.panel'); expect(policy.allow(mockEditAction, testContext)).toBe(true); }); it("disallows editing of plot view when object not a panel type", function () { testViews = [plotView]; - mockTypeCapability.getKey.andReturn('something.else'); + mockTypeCapability.getKey.and.returnValue('something.else'); expect(policy.allow(mockEditAction, testContext)).toBe(false); }); diff --git a/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js b/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js index 4c832d4130..f197abb7b9 100644 --- a/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js @@ -41,20 +41,20 @@ define( mockEditorCapability = jasmine.createSpyObj("editorCapability", ["isEditContextRoot", "inEditContext"]); navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability", "getCapability"]); - navigatedObject.getCapability.andReturn(mockEditorCapability); - navigatedObject.hasCapability.andReturn(false); + navigatedObject.getCapability.and.returnValue(mockEditorCapability); + navigatedObject.hasCapability.and.returnValue(false); mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability", "getCapability"]); - mockDomainObject.hasCapability.andReturn(false); - mockDomainObject.getCapability.andReturn(mockEditorCapability); + mockDomainObject.hasCapability.and.returnValue(false); + mockDomainObject.getCapability.and.returnValue(mockEditorCapability); navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]); - navigationService.getNavigation.andReturn(navigatedObject); + navigationService.getNavigation.and.returnValue(navigatedObject); metadata = {key: "move"}; mockAction = jasmine.createSpyObj("action", ["getMetadata"]); - mockAction.getMetadata.andReturn(metadata); + mockAction.getMetadata.and.returnValue(metadata); context = {domainObject: mockDomainObject}; @@ -67,8 +67,8 @@ define( it('Allows "window" action when navigated object in edit mode,' + ' but selected object not in edit mode ', function () { - navigatedObject.hasCapability.andReturn(true); - mockEditorCapability.isEditContextRoot.andReturn(true); + navigatedObject.hasCapability.and.returnValue(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); metadata.key = "window"; expect(policy.allow(mockAction, context)).toBe(true); }); @@ -79,12 +79,12 @@ define( var mockParent = jasmine.createSpyObj("parentObject", ["hasCapability"]), mockContextCapability = jasmine.createSpyObj("contextCapability", ["getParent"]); - mockParent.hasCapability.andReturn(true); - mockContextCapability.getParent.andReturn(mockParent); - navigatedObject.hasCapability.andReturn(true); + mockParent.hasCapability.and.returnValue(true); + mockContextCapability.getParent.and.returnValue(mockParent); + navigatedObject.hasCapability.and.returnValue(true); - mockDomainObject.getCapability.andReturn(mockContextCapability); - mockDomainObject.hasCapability.andCallFake(function (capability) { + mockDomainObject.getCapability.and.returnValue(mockContextCapability); + mockDomainObject.hasCapability.and.callFake(function (capability) { switch (capability) { case "editor": return false; case "context": return true; @@ -97,19 +97,19 @@ define( it('Disallows "move" action when navigated object in edit mode,' + ' but selected object not in edit mode ', function () { - navigatedObject.hasCapability.andReturn(true); - mockEditorCapability.isEditContextRoot.andReturn(true); - mockEditorCapability.inEditContext.andReturn(false); + navigatedObject.hasCapability.and.returnValue(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); + mockEditorCapability.inEditContext.and.returnValue(false); metadata.key = "move"; expect(policy.allow(mockAction, context)).toBe(false); }); it('Disallows copy action when navigated object and' + ' selected object in edit mode', function () { - navigatedObject.hasCapability.andReturn(true); - mockDomainObject.hasCapability.andReturn(true); - mockEditorCapability.isEditContextRoot.andReturn(true); - mockEditorCapability.inEditContext.andReturn(true); + navigatedObject.hasCapability.and.returnValue(true); + mockDomainObject.hasCapability.and.returnValue(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); + mockEditorCapability.inEditContext.and.returnValue(true); metadata.key = "copy"; expect(policy.allow(mockAction, context)).toBe(false); diff --git a/platform/commonUI/edit/test/policies/EditPersistableObjectsSpec.js b/platform/commonUI/edit/test/policies/EditPersistableObjectsSpec.js index 4615582176..ed9c61bf1d 100644 --- a/platform/commonUI/edit/test/policies/EditPersistableObjectsSpec.js +++ b/platform/commonUI/edit/test/policies/EditPersistableObjectsSpec.js @@ -54,11 +54,11 @@ define( mockPropertiesAction = jasmine.createSpyObj('properties', ['getMetadata']); mockOtherAction = jasmine.createSpyObj('other', ['getMetadata']); - mockEditAction.getMetadata.andReturn({ key: 'edit' }); - mockPropertiesAction.getMetadata.andReturn({ key: 'properties' }); - mockOtherAction.getMetadata.andReturn({key: 'other'}); + mockEditAction.getMetadata.and.returnValue({ key: 'edit' }); + mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' }); + mockOtherAction.getMetadata.and.returnValue({key: 'other'}); - mockDomainObject.getId.andReturn('test:testId'); + mockDomainObject.getId.and.returnValue('test:testId'); testContext = { domainObject: mockDomainObject, @@ -69,7 +69,7 @@ define( }); it("Applies to edit action", function () { - mockObjectAPI.getProvider.andReturn({}); + mockObjectAPI.getProvider.and.returnValue({}); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); policy.allow(mockEditAction, testContext); @@ -77,7 +77,7 @@ define( }); it("Applies to properties action", function () { - mockObjectAPI.getProvider.andReturn({}); + mockObjectAPI.getProvider.and.returnValue({}); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); policy.allow(mockPropertiesAction, testContext); @@ -85,7 +85,7 @@ define( }); it("does not apply to other actions", function () { - mockObjectAPI.getProvider.andReturn({}); + mockObjectAPI.getProvider.and.returnValue({}); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); policy.allow(mockOtherAction, testContext); @@ -93,10 +93,10 @@ define( }); it("Tests object provider for editability", function () { - mockObjectAPI.getProvider.andReturn({}); + mockObjectAPI.getProvider.and.returnValue({}); expect(policy.allow(mockEditAction, testContext)).toBe(false); expect(mockObjectAPI.getProvider).toHaveBeenCalled(); - mockObjectAPI.getProvider.andReturn({save: function () {}}); + mockObjectAPI.getProvider.and.returnValue({save: function () {}}); expect(policy.allow(mockEditAction, testContext)).toBe(true); }); }); diff --git a/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js b/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js index b964cd3339..7b6b97b556 100644 --- a/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js @@ -35,12 +35,12 @@ define( 'domainObject', ['hasCapability', 'getCapability'] ); - mockDomainObject.getCapability.andReturn({ + mockDomainObject.getCapability.and.returnValue({ inEditContext: function () { return true; } }); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return (c === 'editor') && testMode; }); diff --git a/platform/commonUI/edit/test/representers/EditRepresenterSpec.js b/platform/commonUI/edit/test/representers/EditRepresenterSpec.js index 5ebe3d1b83..f1f73aca41 100644 --- a/platform/commonUI/edit/test/representers/EditRepresenterSpec.js +++ b/platform/commonUI/edit/test/representers/EditRepresenterSpec.js @@ -52,8 +52,8 @@ define([ 'useCapability' ]); - domainObject.getId.andReturn('anId'); - domainObject.getModel.andReturn({name: 'anObject'}); + domainObject.getId.and.returnValue('anId'); + domainObject.getModel.and.returnValue({name: 'anObject'}); representation = { key: 'someRepresentation' @@ -75,7 +75,7 @@ define([ expect(domainObject.useCapability) .toHaveBeenCalledWith('mutation', jasmine.any(Function)); - var mutateValue = domainObject.useCapability.calls[0].args[1](); + var mutateValue = domainObject.useCapability.calls.all()[0].args[1](); expect(mutateValue.configuration.someRepresentation) .toEqual({some: 'config'}); diff --git a/platform/commonUI/edit/test/representers/EditToolbarSpec.js b/platform/commonUI/edit/test/representers/EditToolbarSpec.js index 922567b192..b394ff3519 100644 --- a/platform/commonUI/edit/test/representers/EditToolbarSpec.js +++ b/platform/commonUI/edit/test/representers/EditToolbarSpec.js @@ -41,13 +41,13 @@ define( beforeEach(function () { mockOpenMCT = jasmine.createSpy('openmct', ['objects']); mockObjects = jasmine.createSpyObj('objects', ['observe']); - mockObjects.observe.andReturn(); + mockObjects.observe.and.returnValue(); mockOpenMCT.objects = mockObjects; mockScope = jasmine.createSpyObj("$scope", [ "$watchCollection", "$on" ]); - mockScope.$watchCollection.andReturn(); + mockScope.$watchCollection.and.returnValue(); mockDomainObject = jasmine.createSpyObj("domainObject", [ 'identifier' ]); diff --git a/platform/commonUI/edit/test/services/TransactionManagerSpec.js b/platform/commonUI/edit/test/services/TransactionManagerSpec.js index 4d44301893..25b317f3a8 100644 --- a/platform/commonUI/edit/test/services/TransactionManagerSpec.js +++ b/platform/commonUI/edit/test/services/TransactionManagerSpec.js @@ -44,10 +44,10 @@ define( testId = 'test-id'; mockPromise = jasmine.createSpyObj('promise', ['then']); - mockOnCommit.andReturn(mockPromise); - mockOnCancel.andReturn(mockPromise); + mockOnCommit.and.returnValue(mockPromise); + mockOnCancel.and.returnValue(mockPromise); - mockTransactionService.addToTransaction.andCallFake(function () { + mockTransactionService.addToTransaction.and.callFake(function () { var mockRemove = jasmine.createSpy('remove-' + mockRemoves.length); mockRemoves.push(mockRemove); @@ -59,7 +59,7 @@ define( it("delegates isActive calls", function () { [false, true].forEach(function (state) { - mockTransactionService.isActive.andReturn(state); + mockTransactionService.isActive.and.returnValue(state); expect(manager.isActive()).toBe(state); }); }); @@ -84,12 +84,12 @@ define( it("invokes passed-in callbacks from its own callbacks", function () { expect(mockOnCommit).not.toHaveBeenCalled(); mockTransactionService.addToTransaction - .mostRecentCall.args[0](); + .calls.mostRecent().args[0](); expect(mockOnCommit).toHaveBeenCalled(); expect(mockOnCancel).not.toHaveBeenCalled(); mockTransactionService.addToTransaction - .mostRecentCall.args[1](); + .calls.mostRecent().args[1](); expect(mockOnCancel).toHaveBeenCalled(); }); @@ -99,7 +99,7 @@ define( jasmine.createSpy(), jasmine.createSpy() ); - expect(mockTransactionService.addToTransaction.calls.length) + expect(mockTransactionService.addToTransaction.calls.count()) .toEqual(1); }); @@ -109,7 +109,7 @@ define( jasmine.createSpy(), jasmine.createSpy() ); - expect(mockTransactionService.addToTransaction.calls.length) + expect(mockTransactionService.addToTransaction.calls.count()) .toEqual(2); }); diff --git a/platform/commonUI/edit/test/services/TransactionServiceSpec.js b/platform/commonUI/edit/test/services/TransactionServiceSpec.js index 8e96d6b7f8..8ffe4ada55 100644 --- a/platform/commonUI/edit/test/services/TransactionServiceSpec.js +++ b/platform/commonUI/edit/test/services/TransactionServiceSpec.js @@ -40,7 +40,7 @@ define( beforeEach(function () { mockQ = jasmine.createSpyObj("$q", ["all"]); - mockQ.all.andReturn(fastPromise()); + mockQ.all.and.returnValue(fastPromise()); mockLog = jasmine.createSpyObj("$log", ["error"]); transactionService = new TransactionService(mockQ, mockLog); }); diff --git a/platform/commonUI/edit/test/services/TransactionSpec.js b/platform/commonUI/edit/test/services/TransactionSpec.js index 29e512084c..d51eb0bacd 100644 --- a/platform/commonUI/edit/test/services/TransactionSpec.js +++ b/platform/commonUI/edit/test/services/TransactionSpec.js @@ -92,7 +92,7 @@ define( describe("and an exception is encountered during commit", function () { beforeEach(function () { - mockCommit.andCallFake(function () { + mockCommit.and.callFake(function () { throw new Error("test error"); }); transaction.commit(); diff --git a/platform/commonUI/general/test/SplashScreenManagerSpec.js b/platform/commonUI/general/test/SplashScreenManagerSpec.js index 2f27c47599..d143bf346b 100644 --- a/platform/commonUI/general/test/SplashScreenManagerSpec.js +++ b/platform/commonUI/general/test/SplashScreenManagerSpec.js @@ -46,12 +46,12 @@ define([ splashElement.className = 'some-class-name'; - $document.querySelectorAll.andReturn([splashElement]); + $document.querySelectorAll.and.returnValue([splashElement]); }); describe('when element exists', function () { beforeEach(function () { - $document.querySelectorAll.andReturn([splashElement]); + $document.querySelectorAll.and.returnValue([splashElement]); return new SplashScreenManager([$document]); }); @@ -69,14 +69,14 @@ define([ .not .toHaveBeenCalled(); - splashElement.addEventListener.mostRecentCall.args[1](); + splashElement.addEventListener.calls.mostRecent().args[1](); expect(splashElement.parentNode.removeChild) .toHaveBeenCalledWith(splashElement); }); }); it('does not error when element doesn\'t exist', function () { - $document.querySelectorAll.andReturn([]); + $document.querySelectorAll.and.returnValue([]); function run() { return new SplashScreenManager([$document]); diff --git a/platform/commonUI/general/test/StyleSheetLoaderSpec.js b/platform/commonUI/general/test/StyleSheetLoaderSpec.js index 7e4e3481dc..2733b92d70 100644 --- a/platform/commonUI/general/test/StyleSheetLoaderSpec.js +++ b/platform/commonUI/general/test/StyleSheetLoaderSpec.js @@ -52,14 +52,14 @@ define( mockHead = jasmine.createSpyObj("head", ["append"]); mockElement = jasmine.createSpyObj("link", ["setAttribute"]); - mockDocument.find.andReturn(mockHead); - mockPlainDocument.createElement.andReturn(mockElement); + mockDocument.find.and.returnValue(mockHead); + mockPlainDocument.createElement.and.returnValue(mockElement); loader = new StyleSheetLoader(testStyleSheets, mockDocument); }); it("appends one link per stylesheet extension", function () { - expect(mockHead.append.calls.length) + expect(mockHead.append.calls.count()) .toEqual(testStyleSheets.length); }); diff --git a/platform/commonUI/general/test/controllers/ActionGroupControllerSpec.js b/platform/commonUI/general/test/controllers/ActionGroupControllerSpec.js index dd303e8179..1dbe07fcd9 100644 --- a/platform/commonUI/general/test/controllers/ActionGroupControllerSpec.js +++ b/platform/commonUI/general/test/controllers/ActionGroupControllerSpec.js @@ -34,7 +34,7 @@ define( "action" + index, ["perform", "getMetadata"] ); - action.getMetadata.andReturn(metadata); + action.getMetadata.and.returnValue(metadata); return action; } @@ -61,7 +61,7 @@ define( mockScope.action = mockActions; mockScope.parameters = { category: "test" }; - mockActions.getActions.andReturn([ + mockActions.getActions.and.returnValue([ { group: "a", someKey: 0 }, { group: "a", someKey: 1 }, { group: "b", someKey: 2 }, @@ -74,7 +74,7 @@ define( ].map(mockAction)); // Call the watch - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); // Should have grouped and ungrouped actions in scope now expect(mockScope.groups.length).toEqual(2); @@ -85,7 +85,7 @@ define( it("provides empty arrays when no action capability is available", function () { // Call the watch - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); expect(mockScope.groups.length).toEqual(0); expect(mockScope.ungrouped.length).toEqual(0); diff --git a/platform/commonUI/general/test/controllers/ClickAwayControllerSpec.js b/platform/commonUI/general/test/controllers/ClickAwayControllerSpec.js index a0a5cb0091..a24c074a00 100644 --- a/platform/commonUI/general/test/controllers/ClickAwayControllerSpec.js +++ b/platform/commonUI/general/test/controllers/ClickAwayControllerSpec.js @@ -79,9 +79,9 @@ define( it("deactivates and detaches listener on document click", function () { var callback, timeout; controller.setState(true); - callback = mockDocument.on.mostRecentCall.args[1]; + callback = mockDocument.on.calls.mostRecent().args[1]; callback(); - timeout = mockTimeout.mostRecentCall.args[0]; + timeout = mockTimeout.calls.mostRecent().args[0]; timeout(); expect(controller.isActive()).toEqual(false); expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback); diff --git a/platform/commonUI/general/test/controllers/ContextMenuControllerSpec.js b/platform/commonUI/general/test/controllers/ContextMenuControllerSpec.js index 6655519de7..ba695a7477 100644 --- a/platform/commonUI/general/test/controllers/ContextMenuControllerSpec.js +++ b/platform/commonUI/general/test/controllers/ContextMenuControllerSpec.js @@ -47,10 +47,10 @@ define( mockScope.action = mockActions; mockScope.parameters = { category: "test" }; - mockActions.getActions.andReturn(["a", "b", "c"]); + mockActions.getActions.and.returnValue(["a", "b", "c"]); // Call the watch - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); // Should have grouped and ungrouped actions in scope now expect(mockScope.menuActions.length).toEqual(3); diff --git a/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js b/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js index 3beb9f33ae..f1a895cc84 100644 --- a/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js +++ b/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js @@ -33,7 +33,7 @@ define( controller; function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -50,15 +50,15 @@ define( 'format' ]); - mockFormatService.getFormat.andReturn(mockFormat); + mockFormatService.getFormat.and.returnValue(mockFormat); - mockFormat.validate.andCallFake(function (text) { + mockFormat.validate.and.callFake(function (text) { return moment.utc(text, TEST_FORMAT).isValid(); }); - mockFormat.parse.andCallFake(function (text) { + mockFormat.parse.and.callFake(function (text) { return moment.utc(text, TEST_FORMAT).valueOf(); }); - mockFormat.format.andCallFake(function (value) { + mockFormat.format.and.callFake(function (value) { return moment.utc(value).format(TEST_FORMAT); }); @@ -159,8 +159,8 @@ define( var newText = "2015-3-3 01:02:04", oldValue = mockScope.ngModel.testField; - mockFormat.validate.andReturn(true); - mockFormat.parse.andReturn(42); + mockFormat.validate.and.returnValue(true); + mockFormat.parse.and.returnValue(42); mockScope.textValue = newText; fireWatch("textValue", newText); @@ -176,7 +176,7 @@ define( }); it("throws an error for unknown formats", function () { - mockFormatService.getFormat.andReturn(undefined); + mockFormatService.getFormat.and.returnValue(undefined); expect(function () { fireWatch("structure.format", "some-format"); }).toThrow(); @@ -187,9 +187,9 @@ define( testText = "some text"; beforeEach(function () { - mockFormat.validate.andReturn(true); - mockFormat.parse.andReturn(testValue); - mockFormat.format.andReturn(testText); + mockFormat.validate.and.returnValue(true); + mockFormat.parse.and.returnValue(testValue); + mockFormat.format.and.returnValue(testText); }); it("parses user input", function () { diff --git a/platform/commonUI/general/test/controllers/DateTimePickerControllerSpec.js b/platform/commonUI/general/test/controllers/DateTimePickerControllerSpec.js index 66edcbe873..91cf011871 100644 --- a/platform/commonUI/general/test/controllers/DateTimePickerControllerSpec.js +++ b/platform/commonUI/general/test/controllers/DateTimePickerControllerSpec.js @@ -30,7 +30,7 @@ define( controller; function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -38,7 +38,7 @@ define( } function fireWatchCollection(expr, value) { - mockScope.$watchCollection.calls.forEach(function (call) { + mockScope.$watchCollection.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } diff --git a/platform/commonUI/general/test/controllers/GetterSetterControllerSpec.js b/platform/commonUI/general/test/controllers/GetterSetterControllerSpec.js index edcdd5851c..30c0771a9e 100644 --- a/platform/commonUI/general/test/controllers/GetterSetterControllerSpec.js +++ b/platform/commonUI/general/test/controllers/GetterSetterControllerSpec.js @@ -53,7 +53,7 @@ define( expect(mockScope.ngModel) .not.toHaveBeenCalledWith("some new value"); // Fire the matching watcher - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === "getterSetter.value") { call.args[1](mockScope.getterSetter.value); } @@ -64,11 +64,11 @@ define( }); it("updates internal state when external changes are detected", function () { - mockScope.ngModel.andReturn("some other new value"); + mockScope.ngModel.and.returnValue("some other new value"); // Verify precondition expect(mockScope.getterSetter.value).toBeUndefined(); // Fire the matching watcher - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === "ngModel()") { call.args[1]("some other new value"); } diff --git a/platform/commonUI/general/test/controllers/ObjectInspectorControllerSpec.js b/platform/commonUI/general/test/controllers/ObjectInspectorControllerSpec.js index 9972292285..8f5b8e5e4f 100644 --- a/platform/commonUI/general/test/controllers/ObjectInspectorControllerSpec.js +++ b/platform/commonUI/general/test/controllers/ObjectInspectorControllerSpec.js @@ -50,14 +50,14 @@ define( "promise", ["then"] ); - mockObjectService.getObjects.andReturn(mockPromise); + mockObjectService.getObjects.and.returnValue(mockPromise); mockDomainObject = jasmine.createSpyObj( "selectedObject", ["hasCapability", "getCapability", "useCapability", "getModel"] ); - mockDomainObject.getModel.andReturn({location: 'somewhere'}); - mockDomainObject.hasCapability.andReturn(true); + mockDomainObject.getModel.and.returnValue({location: 'somewhere'}); + mockDomainObject.hasCapability.and.returnValue(true); mockContextCapability = jasmine.createSpyObj( "context capability", @@ -68,7 +68,7 @@ define( ["isLink"] ); - mockDomainObject.getCapability.andCallFake(function (param) { + mockDomainObject.getCapability.and.callFake(function (param) { if (param === 'location') { return mockLocationCapability; } else if (param === 'context') { @@ -91,21 +91,21 @@ define( }); it("looks for contextual parent objects", function () { - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); expect(mockContextCapability.getParent).toHaveBeenCalled(); }); it("if link, looks for primary parent objects", function () { - mockLocationCapability.isLink.andReturn(true); + mockLocationCapability.isLink.and.returnValue(true); - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); expect(mockDomainObject.getModel).toHaveBeenCalled(); expect(mockObjectService.getObjects).toHaveBeenCalled(); - mockPromise.then.mostRecentCall.args[0]({'somewhere': mockDomainObject}); + mockPromise.then.calls.mostRecent().args[0]({'somewhere': mockDomainObject}); }); it("gets metadata", function () { - mockScope.$watch.mostRecentCall.args[1](); + mockScope.$watch.calls.mostRecent().args[1](); expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata'); }); }); diff --git a/platform/commonUI/general/test/controllers/SelectorControllerSpec.js b/platform/commonUI/general/test/controllers/SelectorControllerSpec.js index 7665e54162..2e6eaedf2b 100644 --- a/platform/commonUI/general/test/controllers/SelectorControllerSpec.js +++ b/platform/commonUI/general/test/controllers/SelectorControllerSpec.js @@ -45,7 +45,7 @@ define( 'object-' + id, ['getId'] ); - mockObject.getId.andReturn(id); + mockObject.getId.and.returnValue(id); return mockObject; } @@ -72,8 +72,8 @@ define( mockDomainObjects[id] = makeMockObject(id); }); - mockDomainObject.getCapability.andReturn(mockType); - mockObjectService.getObjects.andReturn(promiseOf(mockDomainObjects)); + mockDomainObject.getCapability.and.returnValue(mockType); + mockObjectService.getObjects.and.returnValue(promiseOf(mockDomainObjects)); mockScope.field = "testField"; mockScope.ngModel = {}; @@ -91,27 +91,27 @@ define( it("watches for changes in selection in left-hand tree", function () { var testObject = { a: 123, b: 456 }; // This test is sensitive to ordering of watch calls - expect(mockScope.$watch.calls.length).toEqual(1); + expect(mockScope.$watch.calls.count()).toEqual(1); // Make sure we're watching the correct object controller.treeModel.selectedObject = testObject; - expect(mockScope.$watch.calls[0].args[0]()).toBe(testObject); + expect(mockScope.$watch.calls.all()[0].args[0]()).toBe(testObject); }); it("watches for changes in controlled property", function () { var testValue = ["a", "b", 1, 2]; // This test is sensitive to ordering of watch calls - expect(mockScope.$watchCollection.calls.length).toEqual(1); + expect(mockScope.$watchCollection.calls.count()).toEqual(1); // Make sure we're watching the correct object mockScope.ngModel = { testField: testValue }; - expect(mockScope.$watchCollection.calls[0].args[0]()).toBe(testValue); + expect(mockScope.$watchCollection.calls.all()[0].args[0]()).toBe(testValue); }); it("rejects selection of incorrect types", function () { mockScope.structure = { type: "someType" }; - mockType.instanceOf.andReturn(false); + mockType.instanceOf.and.returnValue(false); controller.treeModel.selectedObject = mockDomainObject; // Fire the watch - mockScope.$watch.calls[0].args[1](mockDomainObject); + mockScope.$watch.calls.all()[0].args[1](mockDomainObject); // Should have cleared the selection expect(controller.treeModel.selectedObject).toBeUndefined(); // Verify interaction (that instanceOf got a useful argument) @@ -120,10 +120,10 @@ define( it("permits selection of matching types", function () { mockScope.structure = { type: "someType" }; - mockType.instanceOf.andReturn(true); + mockType.instanceOf.and.returnValue(true); controller.treeModel.selectedObject = mockDomainObject; // Fire the watch - mockScope.$watch.calls[0].args[1](mockDomainObject); + mockScope.$watch.calls.all()[0].args[1](mockDomainObject); // Should have preserved the selection expect(controller.treeModel.selectedObject).toEqual(mockDomainObject); // Verify interaction (that instanceOf got a useful argument) @@ -133,11 +133,11 @@ define( it("loads objects when the underlying list changes", function () { var testIds = ["abc", "def", "xyz"]; // This test is sensitive to ordering of watch calls - expect(mockScope.$watchCollection.calls.length).toEqual(1); + expect(mockScope.$watchCollection.calls.count()).toEqual(1); // Make sure we're watching the correct object mockScope.ngModel = { testField: testIds }; // Fire the watch - mockScope.$watchCollection.calls[0].args[1](testIds); + mockScope.$watchCollection.calls.all()[0].args[1](testIds); // Should have loaded the corresponding objects expect(mockObjectService.getObjects).toHaveBeenCalledWith(testIds); }); @@ -169,8 +169,8 @@ define( controller.select(mockDomainObjects.def); controller.select(mockDomainObjects.abc); // Fire the watch for the id changes... - mockScope.$watchCollection.calls[0].args[1]( - mockScope.$watchCollection.calls[0].args[0]() + mockScope.$watchCollection.calls.all()[0].args[1]( + mockScope.$watchCollection.calls.all()[0].args[0]() ); // Should have loaded and exposed those objects expect(controller.selected()).toEqual( diff --git a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js index 2b3f756e64..34706ab93a 100644 --- a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js +++ b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js @@ -39,7 +39,7 @@ define( controller; function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -47,7 +47,7 @@ define( } function fireWatchCollection(expr, value) { - mockScope.$watchCollection.calls.forEach(function (call) { + mockScope.$watchCollection.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -73,9 +73,9 @@ define( ["validate", "format", "parse"] ); - mockFormatService.getFormat.andReturn(mockFormat); + mockFormatService.getFormat.and.returnValue(mockFormat); - mockFormat.format.andCallFake(function (value) { + mockFormat.format.and.callFake(function (value) { return moment.utc(value).format("YYYY-MM-DD HH:mm:ss"); }); @@ -300,7 +300,7 @@ define( }); it("throws an error for unknown formats", function () { - mockFormatService.getFormat.andReturn(undefined); + mockFormatService.getFormat.and.returnValue(undefined); expect(function () { fireWatch("parameters.format", "some-format"); }).toThrow(); diff --git a/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js b/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js index 3552d47a38..080726de9e 100644 --- a/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js +++ b/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js @@ -62,7 +62,7 @@ define( // Expansion is tracked on a timeout, because too // much expansion can result in an unstable digest. expect(mockTimeout).toHaveBeenCalled(); - mockTimeout.mostRecentCall.args[0](); + mockTimeout.calls.mostRecent().args[0](); expect(controller.hasBeenExpanded()).toBeTruthy(); controller.trackExpansion(); @@ -77,7 +77,7 @@ define( ), obj = new TestObject("test-object", mockContext); - mockContext.getPath.andReturn([obj]); + mockContext.getPath.and.returnValue([obj]); // Verify precondition expect(controller.isSelected()).toBeFalsy(); @@ -86,7 +86,7 @@ define( mockScope.domainObject = obj; // Invoke the watch with the new selection - mockScope.$watch.calls[0].args[1](obj); + mockScope.$watch.calls.all()[0].args[1](obj); expect(controller.isSelected()).toBeTruthy(); }); @@ -103,9 +103,9 @@ define( parent = new TestObject("parent", mockParentContext), child = new TestObject("child", mockChildContext); - mockChildContext.getParent.andReturn(parent); - mockChildContext.getPath.andReturn([parent, child]); - mockParentContext.getPath.andReturn([parent]); + mockChildContext.getParent.and.returnValue(parent); + mockChildContext.getPath.and.returnValue([parent, child]); + mockParentContext.getPath.and.returnValue([parent]); // Set up such that we are on, but not at the end of, a path mockScope.ngModel = { selectedObject: child }; @@ -113,13 +113,13 @@ define( mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); // Invoke the watch with the new selection - mockScope.$watch.calls[0].args[1](child); + mockScope.$watch.calls.all()[0].args[1](child); // Expansion is tracked on a timeout, because too // much expansion can result in an unstable digest. // Trigger that timeout. expect(mockTimeout).toHaveBeenCalled(); - mockTimeout.mostRecentCall.args[0](); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.toggle.setState).toHaveBeenCalledWith(true); expect(controller.hasBeenExpanded()).toBeTruthy(); @@ -139,9 +139,9 @@ define( parent = new TestObject("parent", mockParentContext), child = new TestObject("child", mockChildContext); - mockChildContext.getParent.andReturn(parent); - mockChildContext.getPath.andReturn([child, child]); - mockParentContext.getPath.andReturn([parent]); + mockChildContext.getParent.and.returnValue(parent); + mockChildContext.getPath.and.returnValue([child, child]); + mockParentContext.getPath.and.returnValue([parent]); // Set up such that we are on, but not at the end of, a path mockScope.ngModel = { selectedObject: child }; @@ -149,7 +149,7 @@ define( mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); // Invoke the watch with the new selection - mockScope.$watch.calls[0].args[1](child); + mockScope.$watch.calls.all()[0].args[1](child); // Expansion is tracked on a timeout, because too // much expansion can result in an unstable digest. @@ -172,9 +172,9 @@ define( parent = new TestObject("parent", mockParentContext), child = new TestObject("child", undefined); - mockChildContext.getParent.andReturn(parent); - mockChildContext.getPath.andReturn([parent, child]); - mockParentContext.getPath.andReturn([parent]); + mockChildContext.getParent.and.returnValue(parent); + mockChildContext.getPath.and.returnValue([parent, child]); + mockParentContext.getPath.and.returnValue([parent]); // Set up such that we are on, but not at the end of, a path mockScope.ngModel = { selectedObject: child }; @@ -182,7 +182,7 @@ define( mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); // Invoke the watch with the new selection - mockScope.$watch.calls[0].args[1](child); + mockScope.$watch.calls.all()[0].args[1](child); expect(mockScope.toggle.setState).not.toHaveBeenCalled(); expect(controller.hasBeenExpanded()).toBeFalsy(); diff --git a/platform/commonUI/general/test/controllers/ViewSwitcherControllerSpec.js b/platform/commonUI/general/test/controllers/ViewSwitcherControllerSpec.js index f81d633a86..f88440b488 100644 --- a/platform/commonUI/general/test/controllers/ViewSwitcherControllerSpec.js +++ b/platform/commonUI/general/test/controllers/ViewSwitcherControllerSpec.js @@ -35,7 +35,7 @@ define( beforeEach(function () { mockScope = jasmine.createSpyObj("$scope", ["$watch"]); mockTimeout = jasmine.createSpy("$timeout"); - mockTimeout.andCallFake(function (cb) { + mockTimeout.and.callFake(function (cb) { cb(); }); mockScope.ngModel = {}; @@ -60,11 +60,11 @@ define( { key: "c", name: "View C" }, { key: "d", name: "View D" } ]; - mockScope.$watch.mostRecentCall.args[1](views); + mockScope.$watch.calls.mostRecent().args[1](views); mockScope.ngModel.selected = views[1]; // Change the set of applicable views - mockScope.$watch.mostRecentCall.args[1]([ + mockScope.$watch.calls.mostRecent().args[1]([ { key: "a", name: "View A" }, { key: "b", name: "View B" }, { key: "x", name: "View X" } @@ -81,11 +81,11 @@ define( { key: "c", name: "View C" }, { key: "d", name: "View D" } ]; - mockScope.$watch.mostRecentCall.args[1](views); + mockScope.$watch.calls.mostRecent().args[1](views); mockScope.ngModel.selected = views[1]; // Change the set of applicable views - mockScope.$watch.mostRecentCall.args[1]([ + mockScope.$watch.calls.mostRecent().args[1]([ { key: "a", name: "View A" }, { key: "c", name: "View C" }, { key: "x", name: "View X" } @@ -102,7 +102,7 @@ define( expect(mockTimeout).not.toHaveBeenCalled(); // Invoke the watch for set of views - mockScope.$watch.mostRecentCall.args[1]([]); + mockScope.$watch.calls.mostRecent().args[1]([]); // Should have run on a timeout expect(mockTimeout).toHaveBeenCalled(); diff --git a/platform/commonUI/general/test/directives/MCTClickElsewhereSpec.js b/platform/commonUI/general/test/directives/MCTClickElsewhereSpec.js index 9377334490..f2d3ff3827 100644 --- a/platform/commonUI/general/test/directives/MCTClickElsewhereSpec.js +++ b/platform/commonUI/general/test/directives/MCTClickElsewhereSpec.js @@ -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 )); diff --git a/platform/commonUI/general/test/directives/MCTDragSpec.js b/platform/commonUI/general/test/directives/MCTDragSpec.js index 1a23d09dbc..c8f0f6dbca 100644 --- a/platform/commonUI/general/test/directives/MCTDragSpec.js +++ b/platform/commonUI/general/test/directives/MCTDragSpec.js @@ -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)); } diff --git a/platform/commonUI/general/test/directives/MCTPopupSpec.js b/platform/commonUI/general/test/directives/MCTPopupSpec.js index 9b5a482863..9884c665c6 100644 --- a/platform/commonUI/general/test/directives/MCTPopupSpec.js +++ b/platform/commonUI/general/test/directives/MCTPopupSpec.js @@ -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](); } diff --git a/platform/commonUI/general/test/directives/MCTResizeSpec.js b/platform/commonUI/general/test/directives/MCTResizeSpec.js index a01a70a542..125269673a 100644 --- a/platform/commonUI/general/test/directives/MCTResizeSpec.js +++ b/platform/commonUI/general/test/directives/MCTResizeSpec.js @@ -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); }); }); diff --git a/platform/commonUI/general/test/directives/MCTScrollSpec.js b/platform/commonUI/general/test/directives/MCTScrollSpec.js index 8d0f14a769..aa5d730855 100644 --- a/platform/commonUI/general/test/directives/MCTScrollSpec.js +++ b/platform/commonUI/general/test/directives/MCTScrollSpec.js @@ -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); }); diff --git a/platform/commonUI/general/test/directives/MCTSplitPaneSpec.js b/platform/commonUI/general/test/directives/MCTSplitPaneSpec.js index 2216eeed70..09ed25f407 100644 --- a/platform/commonUI/general/test/directives/MCTSplitPaneSpec.js +++ b/platform/commonUI/general/test/directives/MCTSplitPaneSpec.js @@ -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 ); diff --git a/platform/commonUI/general/test/directives/MCTSplitterSpec.js b/platform/commonUI/general/test/directives/MCTSplitterSpec.js index 75e2375ec7..8ed70f1d1b 100644 --- a/platform/commonUI/general/test/directives/MCTSplitterSpec.js +++ b/platform/commonUI/general/test/directives/MCTSplitterSpec.js @@ -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 }); diff --git a/platform/commonUI/general/test/directives/MCTTreeSpec.js b/platform/commonUI/general/test/directives/MCTTreeSpec.js index ea12d35b5d..84b0c8da63 100644 --- a/platform/commonUI/general/test/directives/MCTTreeSpec.js +++ b/platform/commonUI/general/test/directives/MCTTreeSpec.js @@ -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'); diff --git a/platform/commonUI/general/test/services/PopupServiceSpec.js b/platform/commonUI/general/test/services/PopupServiceSpec.js index 09048b8a8e..2306af35e8 100644 --- a/platform/commonUI/general/test/services/PopupServiceSpec.js +++ b/platform/commonUI/general/test/services/PopupServiceSpec.js @@ -41,7 +41,7 @@ define( 'remove' ]); - mockDocument.find.andCallFake(function (query) { + mockDocument.find.and.callFake(function (query) { return query === 'body' && mockBody; }); diff --git a/platform/commonUI/general/test/services/UrlServiceSpec.js b/platform/commonUI/general/test/services/UrlServiceSpec.js index 43f1fc29fe..f305e9485c 100644 --- a/platform/commonUI/general/test/services/UrlServiceSpec.js +++ b/platform/commonUI/general/test/services/UrlServiceSpec.js @@ -60,25 +60,25 @@ define( // The mockContext is set a path // for the mockDomainObject - mockContext.getPath.andReturn( + mockContext.getPath.and.returnValue( [mockDomainObject] ); // view capability used with the testviews made - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return (c === 'view') && testViews; }); // context capability used with the mockContext created // so the variables including context in the urlFor are // initialized and reached - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return c === 'context' && mockContext; }); // Uses the mockLocation to get the current // "mock" website's view - mockLocation.search.andReturn({ view: 'def' }); + mockLocation.search.and.returnValue({ view: 'def' }); urlService = new UrlService(mockLocation); }); diff --git a/platform/commonUI/general/test/ui/TreeViewSpec.js b/platform/commonUI/general/test/ui/TreeViewSpec.js index d8acce3b84..44ec36f58d 100644 --- a/platform/commonUI/general/test/ui/TreeViewSpec.js +++ b/platform/commonUI/general/test/ui/TreeViewSpec.js @@ -46,15 +46,15 @@ define([ 'useCapability' ] ); - mockDomainObj.getId.andReturn(id); - mockDomainObj.getModel.andReturn(model); - mockDomainObj.hasCapability.andCallFake(function (c) { + mockDomainObj.getId.and.returnValue(id); + mockDomainObj.getModel.and.returnValue(model); + mockDomainObj.hasCapability.and.callFake(function (c) { return !!(capabilities[c]); }); - mockDomainObj.getCapability.andCallFake(function (c) { + mockDomainObj.getCapability.and.callFake(function (c) { return capabilities[c]; }); - mockDomainObj.useCapability.andCallFake(function (c) { + mockDomainObj.useCapability.and.callFake(function (c) { return capabilities[c] && capabilities[c].invoke(); }); return mockDomainObj; @@ -68,11 +68,11 @@ define([ mockGestureHandle = jasmine.createSpyObj('gestures', ['destroy']); - mockGestureService.attachGestures.andReturn(mockGestureHandle); + mockGestureService.attachGestures.and.returnValue(mockGestureHandle); mockMutation = jasmine.createSpyObj('mutation', ['listen']); mockUnlisten = jasmine.createSpy('unlisten'); - mockMutation.listen.andReturn(mockUnlisten); + mockMutation.listen.and.returnValue(mockUnlisten); testCapabilities = { mutation: mockMutation }; @@ -102,7 +102,7 @@ define([ var mockStatus = jasmine.createSpyObj('status', ['listen', 'list']); - mockStatus.list.andReturn([]); + mockStatus.list.and.returnValue([]); return { context: jasmine.createSpyObj('context', ['getPath']), @@ -113,16 +113,6 @@ define([ }; } - function waitForCompositionCallback() { - var calledBack = false; - testCapabilities.composition.invoke().then(function () { - calledBack = true; - }); - waitsFor(function () { - return calledBack; - }); - } - beforeEach(function () { mockComposition = ['a', 'b', 'c'].map(function (id) { var testCaps = makeGenericCapabilities(), @@ -130,7 +120,7 @@ define([ makeMockDomainObject(id, {}, testCaps); testCaps.context.getPath - .andReturn([mockDomainObject, mockChild]); + .and.returnValue([mockDomainObject, mockChild]); return mockChild; }); @@ -138,10 +128,10 @@ define([ testCapabilities.composition = jasmine.createSpyObj('composition', ['invoke']); testCapabilities.composition.invoke - .andReturn(Promise.resolve(mockComposition)); + .and.returnValue(Promise.resolve(mockComposition)); treeView.model(mockDomainObject); - waitForCompositionCallback(); + return testCapabilities.composition.invoke(); }); it("adds one node per composition element", function () { @@ -158,8 +148,8 @@ define([ beforeEach(function () { mockComposition.pop(); testCapabilities.mutation.listen - .mostRecentCall.args[0](mockDomainObject.getModel()); - waitForCompositionCallback(); + .calls.mostRecent().args[0](mockDomainObject.getModel()); + return testCapabilities.composition.invoke(); }); it("continues to show one node per composition element", function () { @@ -219,38 +209,30 @@ define([ mockNewChild = makeMockDomainObject('d', {}, newCapabilities), mockGrandchild = - makeMockDomainObject('gc', {}, gcCapabilities), - calledBackInner = false; + makeMockDomainObject('gc', {}, gcCapabilities); newCapabilities.composition = jasmine.createSpyObj('composition', ['invoke']); newCapabilities.composition.invoke - .andReturn(Promise.resolve([mockGrandchild])); + .and.returnValue(Promise.resolve([mockGrandchild])); mockComposition.push(mockNewChild); - newCapabilities.context.getPath.andReturn([ + newCapabilities.context.getPath.and.returnValue([ mockDomainObject, mockNewChild ]); - gcCapabilities.context.getPath.andReturn([ + gcCapabilities.context.getPath.and.returnValue([ mockDomainObject, mockNewChild, mockGrandchild ]); testCapabilities.mutation.listen - .mostRecentCall.args[0](mockDomainObject); - waitForCompositionCallback(); - runs(function () { - // Select the innermost object to force expansion, - // such that we can verify the subtree is present. + .calls.mostRecent().args[0](mockDomainObject); + + return testCapabilities.composition.invoke().then(function () { treeView.value(mockGrandchild); - newCapabilities.composition.invoke().then(function () { - calledBackInner = true; - }); - }); - waitsFor(function () { - return calledBackInner; + return newCapabilities.composition.invoke(); }); }); @@ -268,8 +250,8 @@ define([ testStatuses = ['foo']; - mockStatus.list.andReturn(testStatuses); - mockStatus.listen.mostRecentCall.args[0](testStatuses); + mockStatus.list.and.returnValue(testStatuses); + mockStatus.listen.calls.mostRecent().args[0](testStatuses); }); it("reflects the status change in the tree", function () { diff --git a/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js index 8615523b97..d5eedf1540 100644 --- a/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js +++ b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js @@ -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 diff --git a/platform/commonUI/inspect/test/gestures/InfoGestureSpec.js b/platform/commonUI/inspect/test/gestures/InfoGestureSpec.js index 15e1baaf49..6a2a7a35cf 100644 --- a/platform/commonUI/inspect/test/gestures/InfoGestureSpec.js +++ b/platform/commonUI/inspect/test/gestures/InfoGestureSpec.js @@ -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] diff --git a/platform/commonUI/inspect/test/services/InfoServiceSpec.js b/platform/commonUI/inspect/test/services/InfoServiceSpec.js index 1eac6f5b70..274dd26246 100644 --- a/platform/commonUI/inspect/test/services/InfoServiceSpec.js +++ b/platform/commonUI/inspect/test/services/InfoServiceSpec.js @@ -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]); }); diff --git a/platform/commonUI/mobile/test/DeviceClassifierSpec.js b/platform/commonUI/mobile/test/DeviceClassifierSpec.js index 60e6073876..c7dd7046b9 100644 --- a/platform/commonUI/mobile/test/DeviceClassifierSpec.js +++ b/platform/commonUI/mobile/test/DeviceClassifierSpec.js @@ -60,11 +60,11 @@ define( 'body', ['addClass'] ); - mockDocument.find.andCallFake(function (sel) { + mockDocument.find.and.callFake(function (sel) { return sel === 'body' && mockBody; }); AGENT_SERVICE_METHODS.forEach(function (m) { - mockAgentService[m].andReturn(false); + mockAgentService[m].and.returnValue(false); }); }); @@ -78,7 +78,7 @@ define( beforeEach(function () { trueMethods.forEach(function (m) { - mockAgentService[m].andReturn(true); + mockAgentService[m].and.returnValue(true); }); classifier = new DeviceClassifier( mockAgentService, diff --git a/platform/commonUI/mobile/test/DeviceMatchersSpec.js b/platform/commonUI/mobile/test/DeviceMatchersSpec.js index 29b0f4b4f2..2a20914fa6 100644 --- a/platform/commonUI/mobile/test/DeviceMatchersSpec.js +++ b/platform/commonUI/mobile/test/DeviceMatchersSpec.js @@ -43,10 +43,10 @@ define( }); it("detects when a device is a desktop device", function () { - mockAgentService.isMobile.andReturn(false); + mockAgentService.isMobile.and.returnValue(false); expect(DeviceMatchers.desktop(mockAgentService)) .toBe(true); - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); expect(DeviceMatchers.desktop(mockAgentService)) .toBe(false); }); @@ -65,10 +65,10 @@ define( "touch" ].forEach(function (deviceType) { it("detects when a device is a " + deviceType + " device", function () { - mockAgentService[method(deviceType)].andReturn(true); + mockAgentService[method(deviceType)].and.returnValue(true); expect(DeviceMatchers[deviceType](mockAgentService)) .toBe(true); - mockAgentService[method(deviceType)].andReturn(false); + mockAgentService[method(deviceType)].and.returnValue(false); expect(DeviceMatchers[deviceType](mockAgentService)) .toBe(false); }); diff --git a/platform/commonUI/mobile/test/MCTDeviceSpec.js b/platform/commonUI/mobile/test/MCTDeviceSpec.js index f4309fc918..5cfc31274a 100644 --- a/platform/commonUI/mobile/test/MCTDeviceSpec.js +++ b/platform/commonUI/mobile/test/MCTDeviceSpec.js @@ -47,12 +47,12 @@ define( mockElement = jasmine.createSpyObj(name, JQLITE_METHODS); mockClone = jasmine.createSpyObj(name, JQLITE_METHODS); - mockTransclude.andCallFake(function (fn) { + mockTransclude.and.callFake(function (fn) { fn(mockClone); }); // Look desktop-like by default - mockAgentService.isLandscape.andReturn(true); + mockAgentService.isLandscape.and.returnValue(true); testAttrs = {}; @@ -85,40 +85,40 @@ define( link(); expectExclusion(); - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); link(); expectInclusion(); }); it("restricts element inclusion for tablet devices", function () { testAttrs.mctDevice = "tablet"; - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); link(); expectExclusion(); - mockAgentService.isTablet.andReturn(true); + mockAgentService.isTablet.and.returnValue(true); link(); expectInclusion(); }); it("restricts element inclusion for phone devices", function () { testAttrs.mctDevice = "phone"; - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); link(); expectExclusion(); - mockAgentService.isPhone.andReturn(true); + mockAgentService.isPhone.and.returnValue(true); link(); expectInclusion(); }); it("restricts element inclusion for desktop devices", function () { testAttrs.mctDevice = "desktop"; - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); link(); expectExclusion(); - mockAgentService.isMobile.andReturn(false); + mockAgentService.isMobile.and.returnValue(false); link(); expectInclusion(); }); @@ -128,19 +128,19 @@ define( link(); expectExclusion(); - mockAgentService.isPortrait.andReturn(true); + mockAgentService.isPortrait.and.returnValue(true); link(); expectInclusion(); }); it("restricts element inclusion for landscape orientation", function () { testAttrs.mctDevice = "landscape"; - mockAgentService.isLandscape.andReturn(false); - mockAgentService.isPortrait.andReturn(true); + mockAgentService.isLandscape.and.returnValue(false); + mockAgentService.isPortrait.and.returnValue(true); link(); expectExclusion(); - mockAgentService.isLandscape.andReturn(true); + mockAgentService.isLandscape.and.returnValue(true); link(); expectInclusion(); }); @@ -153,13 +153,13 @@ define( // Neither portrait nor mobile, not called expectExclusion(); - mockAgentService.isPortrait.andReturn(true); + mockAgentService.isPortrait.and.returnValue(true); link(); // Was portrait, but not mobile, so no expectExclusion(); - mockAgentService.isMobile.andReturn(true); + mockAgentService.isMobile.and.returnValue(true); link(); expectInclusion(); }); diff --git a/platform/commonUI/notification/test/NotificationIndicatorControllerSpec.js b/platform/commonUI/notification/test/NotificationIndicatorControllerSpec.js index c4ae6e0878..c19c04b0b6 100644 --- a/platform/commonUI/notification/test/NotificationIndicatorControllerSpec.js +++ b/platform/commonUI/notification/test/NotificationIndicatorControllerSpec.js @@ -52,8 +52,8 @@ define( expect(mockScope.showNotificationsList).toBeDefined(); mockScope.showNotificationsList(); expect(mockDialogService.getDialogResponse).toHaveBeenCalled(); - expect(mockDialogService.getDialogResponse.mostRecentCall.args[0]).toBe('overlay-message-list'); - expect(mockDialogService.getDialogResponse.mostRecentCall.args[1].dialog).toBeDefined(); + expect(mockDialogService.getDialogResponse.calls.mostRecent().args[0]).toBe('overlay-message-list'); + expect(mockDialogService.getDialogResponse.calls.mostRecent().args[1].dialog).toBeDefined(); }); }); } diff --git a/platform/commonUI/notification/test/NotificationServiceSpec.js b/platform/commonUI/notification/test/NotificationServiceSpec.js index 3080b537a0..bc315eba46 100644 --- a/platform/commonUI/notification/test/NotificationServiceSpec.js +++ b/platform/commonUI/notification/test/NotificationServiceSpec.js @@ -37,14 +37,14 @@ define( errorModel; function elapseTimeout() { - mockTimeout.mostRecentCall.args[0](); + mockTimeout.calls.mostRecent().args[0](); } beforeEach(function () { mockTimeout = jasmine.createSpy("$timeout"); mockTopicFunction = jasmine.createSpy("topic"); mockTopicObject = jasmine.createSpyObj("topicObject", ["listen", "notify"]); - mockTopicFunction.andReturn(mockTopicObject); + mockTopicFunction.and.returnValue(mockTopicObject); mockAutoDismiss = mockMinimizeTimeout = 1000; notificationService = new NotificationService(mockTimeout, mockTopicFunction, mockAutoDismiss, mockMinimizeTimeout); @@ -72,7 +72,7 @@ define( expect(mockTopicObject.listen).toHaveBeenCalled(); notification.dismiss(); expect(mockTopicObject.notify).toHaveBeenCalled(); - mockTopicObject.listen.mostRecentCall.args[0](); + mockTopicObject.listen.calls.mostRecent().args[0](); expect(dismissListener).toHaveBeenCalled(); }); @@ -132,7 +132,7 @@ define( }); it("keeps alert notifications active if the caller disables auto-dismiss", function () { - mockTimeout.andCallFake(function (callback, time) { + mockTimeout.and.callFake(function (callback, time) { callback(); }); alertModel.autoDismiss = false; @@ -143,7 +143,7 @@ define( }); it("keeps alert notifications active if the caller ignores auto-dismiss", function () { - mockTimeout.andCallFake(function (callback, time) { + mockTimeout.and.callFake(function (callback, time) { callback(); }); var notification = notificationService.alert(alertModel); @@ -165,7 +165,7 @@ define( }); it("keeps error notifications active if the caller disables auto-dismiss", function () { - mockTimeout.andCallFake(function (callback, time) { + mockTimeout.and.callFake(function (callback, time) { callback(); }); errorModel.autoDismiss = false; @@ -176,7 +176,7 @@ define( }); it("keeps error notifications active if the caller ignores auto-dismiss", function () { - mockTimeout.andCallFake(function (callback, time) { + mockTimeout.and.callFake(function (callback, time) { callback(); }); var notification = notificationService.error(errorModel); diff --git a/platform/commonUI/regions/test/EditableRegionPolicySpec.js b/platform/commonUI/regions/test/EditableRegionPolicySpec.js index 3cc5c768b4..f8fcc30960 100644 --- a/platform/commonUI/regions/test/EditableRegionPolicySpec.js +++ b/platform/commonUI/regions/test/EditableRegionPolicySpec.js @@ -46,26 +46,26 @@ define( mockDomainObject = jasmine.createSpyObj("domainObject", [ "hasCapability", "getCapability" ]); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andReturn(mockEditorCapability); + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.returnValue(mockEditorCapability); }); it("includes only browse region parts for object not in edit mode", function () { - mockEditorCapability.inEditContext.andReturn(false); + mockEditorCapability.inEditContext.and.returnValue(false); expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(true); expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(false); }); it("includes only edit region parts for object in edit mode", function () { - mockEditorCapability.inEditContext.andReturn(true); + mockEditorCapability.inEditContext.and.returnValue(true); expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(false); expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(true); }); it("includes region parts with no mode specification", function () { - mockEditorCapability.inEditContext.andReturn(false); + mockEditorCapability.inEditContext.and.returnValue(false); expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true); - mockEditorCapability.inEditContext.andReturn(true); + mockEditorCapability.inEditContext.and.returnValue(true); expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true); }); diff --git a/platform/commonUI/regions/test/InspectorControllerSpec.js b/platform/commonUI/regions/test/InspectorControllerSpec.js index d0bc14b2d8..99b3d757f0 100644 --- a/platform/commonUI/regions/test/InspectorControllerSpec.js +++ b/platform/commonUI/regions/test/InspectorControllerSpec.js @@ -46,7 +46,7 @@ define( mockDomainObject = jasmine.createSpyObj('domainObject', [ 'getCapability' ]); - mockDomainObject.getCapability.andReturn(mockTypeDef); + mockDomainObject.getCapability.and.returnValue(mockTypeDef); mockScope = jasmine.createSpyObj('$scope', ['$on', 'selection'] @@ -63,7 +63,7 @@ define( 'off', 'get' ]); - mockSelection.get.andReturn(selectable); + mockSelection.get.and.returnValue(selectable); mockInspectorViews = jasmine.createSpyObj('inspectorViews', ['get']); mockOpenMCT = { @@ -73,7 +73,7 @@ define( container = jasmine.createSpy('container', ['innerHTML']); $document[0] = jasmine.createSpyObj("$document", ['querySelectorAll']); - $document[0].querySelectorAll.andReturn([container]); + $document[0].querySelectorAll.and.returnValue([container]); controller = new InspectorController(mockScope, mockOpenMCT, $document); }); @@ -89,10 +89,10 @@ define( var mockItem = jasmine.createSpyObj('domainObject', [ 'getCapability' ]); - mockItem.getCapability.andReturn(mockTypeDef); + mockItem.getCapability.and.returnValue(mockTypeDef); selectable[0].context.oldItem = mockItem; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(controller.selectedItem()).toEqual(mockItem); }); @@ -103,7 +103,7 @@ define( jasmine.any(Function) ); - mockScope.$on.calls[0].args[1](); + mockScope.$on.calls.all()[0].args[1](); expect(mockOpenMCT.selection.off).toHaveBeenCalledWith( 'change', diff --git a/platform/containment/test/ComposeActionPolicySpec.js b/platform/containment/test/ComposeActionPolicySpec.js index f409579d34..23b3b8cda4 100644 --- a/platform/containment/test/ComposeActionPolicySpec.js +++ b/platform/containment/test/ComposeActionPolicySpec.js @@ -40,7 +40,7 @@ define( ); mockTypes = ['a', 'b'].map(function (type) { var mockType = jasmine.createSpyObj('type-' + type, ['getKey']); - mockType.getKey.andReturn(type); + mockType.getKey.and.returnValue(type); return mockType; }); mockDomainObjects = ['a', 'b'].map(function (id, index) { @@ -48,8 +48,8 @@ define( 'domainObject-' + id, ['getId', 'getCapability'] ); - mockDomainObject.getId.andReturn(id); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getId.and.returnValue(id); + mockDomainObject.getCapability.and.callFake(function (c) { return c === 'type' && mockTypes[index]; }); return mockDomainObject; @@ -62,8 +62,8 @@ define( selectedObject: mockDomainObjects[1] }; - mockAction.getMetadata.andReturn(testContext); - mockInjector.get.andCallFake(function (service) { + mockAction.getMetadata.and.returnValue(testContext); + mockInjector.get.and.callFake(function (service) { return service === 'policyService' && mockPolicyService; }); @@ -71,9 +71,9 @@ define( }); it("defers to composition policy", function () { - mockPolicyService.allow.andReturn(false); + mockPolicyService.allow.and.returnValue(false); expect(policy.allow(mockAction, testContext)).toBeFalsy(); - mockPolicyService.allow.andReturn(true); + mockPolicyService.allow.and.returnValue(true); expect(policy.allow(mockAction, testContext)).toBeTruthy(); expect(mockPolicyService.allow).toHaveBeenCalledWith( @@ -85,7 +85,7 @@ define( it("allows actions other than compose", function () { testContext.key = 'somethingElse'; - mockPolicyService.allow.andReturn(false); + mockPolicyService.allow.and.returnValue(false); expect(policy.allow(mockAction, testContext)).toBeTruthy(); }); }); diff --git a/platform/containment/test/CompositionModelPolicySpec.js b/platform/containment/test/CompositionModelPolicySpec.js index 3165312179..c2ebb9e45d 100644 --- a/platform/containment/test/CompositionModelPolicySpec.js +++ b/platform/containment/test/CompositionModelPolicySpec.js @@ -19,9 +19,9 @@ define( }); it("only allows composition for types which will have a composition property", function () { - mockType.getInitialModel.andReturn({}); + mockType.getInitialModel.and.returnValue({}); expect(policy.allow(mockObject)).toBeFalsy(); - mockType.getInitialModel.andReturn({ composition: [] }); + mockType.getInitialModel.and.returnValue({ composition: [] }); expect(policy.allow(mockObject)).toBeTruthy(); }); }); diff --git a/platform/containment/test/CompositionMutabilityPolicySpec.js b/platform/containment/test/CompositionMutabilityPolicySpec.js index 0cf8dbf7eb..009ae135eb 100644 --- a/platform/containment/test/CompositionMutabilityPolicySpec.js +++ b/platform/containment/test/CompositionMutabilityPolicySpec.js @@ -41,7 +41,7 @@ define( it("only allows composition for types which can be created/modified", function () { expect(policy.allow(mockObject)).toBeFalsy(); - mockType.hasFeature.andReturn(true); + mockType.hasFeature.and.returnValue(true); expect(policy.allow(mockObject)).toBeTruthy(); expect(mockType.hasFeature).toHaveBeenCalledWith('creation'); }); diff --git a/platform/containment/test/CompositionPolicySpec.js b/platform/containment/test/CompositionPolicySpec.js index 6cc7a4ac73..6ec25f2fe3 100644 --- a/platform/containment/test/CompositionPolicySpec.js +++ b/platform/containment/test/CompositionPolicySpec.js @@ -40,8 +40,8 @@ define( 'type A-- the particular kind', ['getKey', 'getDefinition'] ); - typeA.getKey.andReturn('a'); - typeA.getDefinition.andReturn({ + typeA.getKey.and.returnValue('a'); + typeA.getDefinition.and.returnValue({ contains: ['a'] }); @@ -50,8 +50,8 @@ define( 'type B-- anything goes', ['getKey', 'getDefinition'] ); - typeB.getKey.andReturn('b'); - typeB.getDefinition.andReturn({ + typeB.getKey.and.returnValue('b'); + typeB.getDefinition.and.returnValue({ contains: ['a', 'b'] }); @@ -59,8 +59,8 @@ define( 'type C-- distinguishing and interested in telemetry', ['getKey', 'getDefinition'] ); - typeC.getKey.andReturn('c'); - typeC.getDefinition.andReturn({ + typeC.getKey.and.returnValue('c'); + typeC.getDefinition.and.returnValue({ contains: [{has: 'telemetry'}] }); @@ -75,17 +75,17 @@ define( describe('enforces simple containment rules', function () { it('allows when type matches', function () { - mockParentObject.getCapability.andReturn(typeA); + mockParentObject.getCapability.and.returnValue(typeA); - mockChildObject.getCapability.andReturn(typeA); + mockChildObject.getCapability.and.returnValue(typeA); expect(policy.allow(mockParentObject, mockChildObject)) .toBeTruthy(); - mockParentObject.getCapability.andReturn(typeB); + mockParentObject.getCapability.and.returnValue(typeB); expect(policy.allow(mockParentObject, mockChildObject)) .toBeTruthy(); - mockChildObject.getCapability.andReturn(typeB); + mockChildObject.getCapability.and.returnValue(typeB); expect(policy.allow(mockParentObject, mockChildObject)) .toBeTruthy(); }); @@ -93,12 +93,12 @@ define( it('disallows when type doesn\'t match', function () { - mockParentObject.getCapability.andReturn(typeA); - mockChildObject.getCapability.andReturn(typeB); + mockParentObject.getCapability.and.returnValue(typeA); + mockChildObject.getCapability.and.returnValue(typeB); expect(policy.allow(mockParentObject, mockChildObject)) .toBeFalsy(); - mockChildObject.getCapability.andReturn(typeC); + mockChildObject.getCapability.and.returnValue(typeC); expect(policy.allow(mockParentObject, mockChildObject)) .toBeFalsy(); }); @@ -107,9 +107,9 @@ define( describe('enforces capability-based containment rules', function () { it('allows when object has capability', function () { - mockParentObject.getCapability.andReturn(typeC); + mockParentObject.getCapability.and.returnValue(typeC); - mockChildObject.hasCapability.andReturn(true); + mockChildObject.hasCapability.and.returnValue(true); expect(policy.allow(mockParentObject, mockChildObject)) .toBeTruthy(); expect(mockChildObject.hasCapability) @@ -117,9 +117,9 @@ define( }); it('skips when object doesn\'t have capability', function () { - mockChildObject.hasCapability.andReturn(false); + mockChildObject.hasCapability.and.returnValue(false); - mockParentObject.getCapability.andReturn(typeC); + mockParentObject.getCapability.and.returnValue(typeC); expect(policy.allow(mockParentObject, mockChildObject)) .toBeFalsy(); diff --git a/platform/containment/test/PersistableCompositionPolicySpec.js b/platform/containment/test/PersistableCompositionPolicySpec.js index 56c4ce6575..f06ef7d16b 100644 --- a/platform/containment/test/PersistableCompositionPolicySpec.js +++ b/platform/containment/test/PersistableCompositionPolicySpec.js @@ -44,15 +44,15 @@ define( 'getCapability', 'getId' ]); - mockParent.hasCapability.andReturn(true); - mockParent.getId.andReturn('someNamespace:someId'); + mockParent.hasCapability.and.returnValue(true); + mockParent.getId.and.returnValue('someNamespace:someId'); mockChild = {}; mockEditorCapability = jasmine.createSpyObj('domainObject', [ 'isEditContextRoot' ]); - mockParent.getCapability.andReturn(mockEditorCapability); + mockParent.getCapability.and.returnValue(mockEditorCapability); - objectAPI.getProvider.andReturn({ + objectAPI.getProvider.and.returnValue({ save: function () {} }); persistableCompositionPolicy = new PersistableCompositionPolicy(mockOpenMCT); @@ -64,18 +64,18 @@ define( // - openMct.objects.getProvider it("Does not allow composition for objects that are not persistable", function () { - mockEditorCapability.isEditContextRoot.andReturn(false); + mockEditorCapability.isEditContextRoot.and.returnValue(false); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); - objectAPI.getProvider.andReturn({}); + objectAPI.getProvider.and.returnValue({}); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(false); }); it("Always allows composition of objects in edit mode to support object creation", function () { - mockEditorCapability.isEditContextRoot.andReturn(true); + mockEditorCapability.isEditContextRoot.and.returnValue(true); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); expect(objectAPI.getProvider).not.toHaveBeenCalled(); - mockEditorCapability.isEditContextRoot.andReturn(false); + mockEditorCapability.isEditContextRoot.and.returnValue(false); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); expect(objectAPI.getProvider).toHaveBeenCalled(); }); diff --git a/platform/core/src/actions/ActionCapability.js b/platform/core/src/actions/ActionCapability.js index 4cd959a485..48cfa0bdf8 100644 --- a/platform/core/src/actions/ActionCapability.js +++ b/platform/core/src/actions/ActionCapability.js @@ -24,8 +24,8 @@ * Module defining ActionCapability. Created by vwoeltje on 11/10/14. */ define( - [], - function () { + ['lodash'], + function (_) { /** * The ActionCapability allows applicable Actions to be retrieved and @@ -74,10 +74,14 @@ define( // Get all actions which are valid in this context; // this simply redirects to the action service, // but additionally adds a domainObject field. - var baseContext = typeof context === 'string' ? - { key: context } : (context || {}), - actionContext = Object.create(baseContext); + var baseContext; + if (typeof context === 'string') { + baseContext = { key: context }; + } else { + baseContext = context || {}; + } + var actionContext = _.extend({}, baseContext); actionContext.domainObject = this.domainObject; return this.actionService.getActions(actionContext); diff --git a/platform/core/test/actions/ActionAggregatorSpec.js b/platform/core/test/actions/ActionAggregatorSpec.js index a7ef3ef33c..2eac74ff14 100644 --- a/platform/core/test/actions/ActionAggregatorSpec.js +++ b/platform/core/test/actions/ActionAggregatorSpec.js @@ -33,7 +33,7 @@ define( function createMockActionProvider(actions, i) { var spy = jasmine.createSpyObj("agg" + i, ["getActions"]); - spy.getActions.andReturn(actions); + spy.getActions.and.returnValue(actions); return spy; } diff --git a/platform/core/test/actions/ActionCapabilitySpec.js b/platform/core/test/actions/ActionCapabilitySpec.js index 63b5e08246..b03e704b48 100644 --- a/platform/core/test/actions/ActionCapabilitySpec.js +++ b/platform/core/test/actions/ActionCapabilitySpec.js @@ -52,7 +52,7 @@ define( ["getId", "getModel", "getCapability", "hasCapability", "useCapability"] ); - mockActionService.getActions.andReturn([mockAction, {}]); + mockActionService.getActions.and.returnValue([mockAction, {}]); capability = new ActionCapability( mockQ, @@ -77,8 +77,8 @@ define( it("promises the result of performed actions", function () { var mockPromise = jasmine.createSpyObj("promise", ["then"]); - mockQ.when.andReturn(mockPromise); - mockAction.perform.andReturn("the action's result"); + mockQ.when.and.returnValue(mockPromise); + mockAction.perform.and.returnValue("the action's result"); // Verify precondition expect(mockAction.perform).not.toHaveBeenCalled(); diff --git a/platform/core/test/actions/ActionProviderSpec.js b/platform/core/test/actions/ActionProviderSpec.js index 2c0d60fc27..60017e80e2 100644 --- a/platform/core/test/actions/ActionProviderSpec.js +++ b/platform/core/test/actions/ActionProviderSpec.js @@ -176,7 +176,7 @@ define( it("reports the error's message", function () { expect( - mockLog.error.mostRecentCall.args[0].indexOf(errorText) + mockLog.error.calls.mostRecent().args[0].indexOf(errorText) ).not.toEqual(-1); }); diff --git a/platform/core/test/actions/LoggingActionDecoratorSpec.js b/platform/core/test/actions/LoggingActionDecoratorSpec.js index 858f262b92..4cd0f37d77 100644 --- a/platform/core/test/actions/LoggingActionDecoratorSpec.js +++ b/platform/core/test/actions/LoggingActionDecoratorSpec.js @@ -47,7 +47,7 @@ define( ["error", "warn", "info", "debug"] ); - mockActionService.getActions.andReturn([mockAction]); + mockActionService.getActions.and.returnValue([mockAction]); decorator = new LoggingActionDecorator( mockLog, diff --git a/platform/core/test/capabilities/CompositionCapabilitySpec.js b/platform/core/test/capabilities/CompositionCapabilitySpec.js index 0a944e6b08..16b5827270 100644 --- a/platform/core/test/capabilities/CompositionCapabilitySpec.js +++ b/platform/core/test/capabilities/CompositionCapabilitySpec.js @@ -72,7 +72,7 @@ define( } }; - mockObjectService.getObjects.andReturn(mockPromise([])); + mockObjectService.getObjects.and.returnValue(mockPromise([])); composition = new CompositionCapability( mockInjector, @@ -90,7 +90,7 @@ define( it("requests ids found in model's composition from the object service", function () { var ids = ["a", "b", "c", "xyz"]; - mockDomainObject.getModel.andReturn({ composition: ids }); + mockDomainObject.getModel.and.returnValue({ composition: ids }); composition.invoke(); @@ -101,9 +101,9 @@ define( var result, mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); - mockDomainObject.getModel.andReturn({ composition: ["x"] }); - mockObjectService.getObjects.andReturn(mockPromise({x: mockChild})); - mockChild.getCapability.andReturn(undefined); + mockDomainObject.getModel.and.returnValue({ composition: ["x"] }); + mockObjectService.getObjects.and.returnValue(mockPromise({x: mockChild})); + mockChild.getCapability.and.returnValue(undefined); composition.invoke().then(function (c) { result = c; @@ -119,12 +119,12 @@ define( testModel = { composition: [] }, mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); - mockDomainObject.getModel.andReturn(testModel); - mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); - mockChild.getCapability.andReturn(undefined); - mockChild.getId.andReturn('a'); + mockDomainObject.getModel.and.returnValue(testModel); + mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild})); + mockChild.getCapability.and.returnValue(undefined); + mockChild.getId.and.returnValue('a'); - mockDomainObject.useCapability.andCallFake(function (key, mutator) { + mockDomainObject.useCapability.and.callFake(function (key, mutator) { if (key === 'mutation') { mutator(testModel); return mockPromise(true); @@ -149,12 +149,12 @@ define( testModel = { composition: ['a'] }, mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); - mockDomainObject.getModel.andReturn(testModel); - mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); - mockChild.getCapability.andReturn(undefined); - mockChild.getId.andReturn('a'); + mockDomainObject.getModel.and.returnValue(testModel); + mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild})); + mockChild.getCapability.and.returnValue(undefined); + mockChild.getId.and.returnValue('a'); - mockDomainObject.useCapability.andCallFake(function (key, mutator) { + mockDomainObject.useCapability.and.callFake(function (key, mutator) { if (key === 'mutation') { mutator(testModel); return mockPromise(true); @@ -180,12 +180,12 @@ define( testModel = { composition: ['a', 'b', 'c'] }, mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); - mockDomainObject.getModel.andReturn(testModel); - mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); - mockChild.getCapability.andReturn(undefined); - mockChild.getId.andReturn('a'); + mockDomainObject.getModel.and.returnValue(testModel); + mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild})); + mockChild.getCapability.and.returnValue(undefined); + mockChild.getId.and.returnValue('a'); - mockDomainObject.useCapability.andCallFake(function (key, mutator) { + mockDomainObject.useCapability.and.callFake(function (key, mutator) { if (key === 'mutation') { mutator(testModel); return mockPromise(true); diff --git a/platform/core/test/capabilities/ContextCapabilitySpec.js b/platform/core/test/capabilities/ContextCapabilitySpec.js index 2d6b12ee9e..208f2e299c 100644 --- a/platform/core/test/capabilities/ContextCapabilitySpec.js +++ b/platform/core/test/capabilities/ContextCapabilitySpec.js @@ -48,10 +48,10 @@ define( mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS); mockContext = jasmine.createSpyObj("context", ["getParent", "getRoot", "getPath"]); - mockParent.getCapability.andReturn(mockContext); - mockContext.getParent.andReturn(mockGrandparent); - mockContext.getRoot.andReturn(mockGrandparent); - mockContext.getPath.andReturn([mockGrandparent, mockParent]); + mockParent.getCapability.and.returnValue(mockContext); + mockContext.getParent.and.returnValue(mockGrandparent); + mockContext.getRoot.and.returnValue(mockGrandparent); + mockContext.getPath.and.returnValue([mockGrandparent, mockParent]); context = new ContextCapability(mockParent, mockDomainObject); }); @@ -69,7 +69,7 @@ define( }); it("treats ancestors with no context capability as deepest ancestors", function () { - mockParent.getCapability.andReturn(undefined); + mockParent.getCapability.and.returnValue(undefined); expect(context.getPath()).toEqual([mockParent, mockDomainObject]); expect(context.getRoot()).toEqual(mockParent); }); diff --git a/platform/core/test/capabilities/ContextualDomainObjectSpec.js b/platform/core/test/capabilities/ContextualDomainObjectSpec.js index d7cc5d4986..8ac13f877c 100644 --- a/platform/core/test/capabilities/ContextualDomainObjectSpec.js +++ b/platform/core/test/capabilities/ContextualDomainObjectSpec.js @@ -49,8 +49,8 @@ define( model = { someKey: "some value" }; - mockDomainObject.getCapability.andReturn("some capability"); - mockDomainObject.getModel.andReturn(model); + mockDomainObject.getCapability.and.returnValue("some capability"); + mockDomainObject.getModel.and.returnValue(model); contextualDomainObject = new ContextualDomainObject( mockDomainObject, diff --git a/platform/core/test/capabilities/CoreCapabilityProviderSpec.js b/platform/core/test/capabilities/CoreCapabilityProviderSpec.js index 9a34cc3cc0..6e7a88a41c 100644 --- a/platform/core/test/capabilities/CoreCapabilityProviderSpec.js +++ b/platform/core/test/capabilities/CoreCapabilityProviderSpec.js @@ -49,6 +49,8 @@ define( } beforeEach(function () { + KeylessCapability.key = undefined; + mockLog = jasmine.createSpyObj( "$log", ["error", "warn", "info", "debug"] diff --git a/platform/core/test/capabilities/InstantiationCapabilitySpec.js b/platform/core/test/capabilities/InstantiationCapabilitySpec.js index 960ddbfe37..6b5bc77374 100644 --- a/platform/core/test/capabilities/InstantiationCapabilitySpec.js +++ b/platform/core/test/capabilities/InstantiationCapabilitySpec.js @@ -49,16 +49,16 @@ define( ['getId', 'getCapability', 'getModel'] ); - mockInjector.get.andCallFake(function (key) { + mockInjector.get.and.callFake(function (key) { return { 'instantiate': mockInstantiate }[key]; }); - mockIdentifierService.parse.andReturn(mockIdentifier); - mockIdentifierService.generate.andReturn("some-id"); + mockIdentifierService.parse.and.returnValue(mockIdentifier); + mockIdentifierService.generate.and.returnValue("some-id"); mockNow = jasmine.createSpy(); - mockNow.andReturn(1234321); + mockNow.and.returnValue(1234321); instantiation = new InstantiationCapability( mockInjector, @@ -81,7 +81,7 @@ define( 'useCapability', 'hasCapability' ]), testModel = { someKey: "some value" }; - mockInstantiate.andReturn(mockDomainObj); + mockInstantiate.and.returnValue(mockDomainObj); instantiation.instantiate(testModel); expect(mockInstantiate) .toHaveBeenCalledWith({ diff --git a/platform/core/test/capabilities/MetadataCapabilitySpec.js b/platform/core/test/capabilities/MetadataCapabilitySpec.js index 7c36fb2ae2..d1f22b869b 100644 --- a/platform/core/test/capabilities/MetadataCapabilitySpec.js +++ b/platform/core/test/capabilities/MetadataCapabilitySpec.js @@ -58,18 +58,18 @@ define( 'property-' + k, ['getValue', 'getDefinition'] ); - mockProperty.getValue.andReturn("Value " + k); - mockProperty.getDefinition.andReturn({ name: "Property " + k}); + mockProperty.getValue.and.returnValue("Value " + k); + mockProperty.getDefinition.and.returnValue({ name: "Property " + k}); return mockProperty; }); testModel = { name: "" }; - mockDomainObject.getId.andReturn("Test id"); - mockDomainObject.getModel.andReturn(testModel); - mockDomainObject.getCapability.andCallFake(getCapability); - mockDomainObject.useCapability.andCallFake(getCapability); - mockType.getProperties.andReturn(mockProperties); - mockType.getName.andReturn("Test type"); + mockDomainObject.getId.and.returnValue("Test id"); + mockDomainObject.getModel.and.returnValue(testModel); + mockDomainObject.getCapability.and.callFake(getCapability); + mockDomainObject.useCapability.and.callFake(getCapability); + mockType.getProperties.and.returnValue(mockProperties); + mockType.getName.and.returnValue("Test type"); metadata = new MetadataCapability(mockDomainObject); }); diff --git a/platform/core/test/capabilities/MutationCapabilitySpec.js b/platform/core/test/capabilities/MutationCapabilitySpec.js index 61791d1f04..9df4bd9206 100644 --- a/platform/core/test/capabilities/MutationCapabilitySpec.js +++ b/platform/core/test/capabilities/MutationCapabilitySpec.js @@ -48,7 +48,7 @@ define( testModel = { number: 6 }; topic = new Topic(); mockNow = jasmine.createSpy('now'); - mockNow.andReturn(12321); + mockNow.and.returnValue(12321); mutation = new MutationCapability( topic, mockNow, @@ -105,7 +105,7 @@ define( m.number = 8; }); expect(mockCallback).toHaveBeenCalled(); - expect(mockCallback.mostRecentCall.args[0].number) + expect(mockCallback.calls.mostRecent().args[0].number) .toEqual(8); }); @@ -130,7 +130,7 @@ define( m.number = 8; }); expect(mockCallback).toHaveBeenCalled(); - expect(mockCallback.mostRecentCall.args[0].number) + expect(mockCallback.calls.mostRecent().args[0].number) .toEqual(8); }); }); diff --git a/platform/core/test/capabilities/PersistenceCapabilitySpec.js b/platform/core/test/capabilities/PersistenceCapabilitySpec.js index c3cfe40c0b..94dfc2ae85 100644 --- a/platform/core/test/capabilities/PersistenceCapabilitySpec.js +++ b/platform/core/test/capabilities/PersistenceCapabilitySpec.js @@ -95,15 +95,15 @@ define( useCapability: jasmine.createSpy() }; // Simulate mutation capability - mockDomainObject.useCapability.andCallFake(function (capability, mutator) { + mockDomainObject.useCapability.and.callFake(function (capability, mutator) { if (capability === 'mutation') { model = mutator(model) || model; } }); - mockIdentifierService.parse.andReturn(mockIdentifier); - mockIdentifier.getSpace.andReturn(SPACE); - mockIdentifier.getKey.andReturn(key); - mockQ.when.andCallFake(asPromise); + mockIdentifierService.parse.and.returnValue(mockIdentifier); + mockIdentifier.getSpace.and.returnValue(SPACE); + mockIdentifier.getKey.and.returnValue(key); + mockQ.when.and.callFake(asPromise); persistence = new PersistenceCapability( mockCacheService, mockPersistenceService, @@ -116,8 +116,8 @@ define( describe("successful persistence", function () { beforeEach(function () { - mockPersistenceService.updateObject.andReturn(happyPromise); - mockPersistenceService.createObject.andReturn(happyPromise); + mockPersistenceService.updateObject.and.returnValue(happyPromise); + mockPersistenceService.createObject.and.returnValue(happyPromise); }); it("creates unpersisted objects with the persistence service", function () { // Verify precondition; no call made during constructor @@ -158,7 +158,7 @@ define( it("refreshes the domain object model from persistence", function () { var refreshModel = {someOtherKey: "some other value"}; model.persisted = 1; - mockPersistenceService.readObject.andReturn(asPromise(refreshModel)); + mockPersistenceService.readObject.and.returnValue(asPromise(refreshModel)); persistence.refresh(); expect(model).toEqual(refreshModel); }); @@ -178,7 +178,7 @@ define( } }; beforeEach(function () { - mockPersistenceService.createObject.andReturn(sadPromise); + mockPersistenceService.createObject.and.returnValue(sadPromise); }); it("rejects on falsey persistence result", function () { persistence.persist(); diff --git a/platform/core/test/capabilities/RelationshipCapabilitySpec.js b/platform/core/test/capabilities/RelationshipCapabilitySpec.js index c0ab3215a6..d084e886c8 100644 --- a/platform/core/test/capabilities/RelationshipCapabilitySpec.js +++ b/platform/core/test/capabilities/RelationshipCapabilitySpec.js @@ -69,7 +69,7 @@ define( } }; - mockObjectService.getObjects.andReturn(mockPromise([])); + mockObjectService.getObjects.and.returnValue(mockPromise([])); relationship = new RelationshipCapability( mockInjector, @@ -87,7 +87,7 @@ define( it("requests ids found in model's composition from the object service", function () { var ids = ["a", "b", "c", "xyz"]; - mockDomainObject.getModel.andReturn({ relationships: { xyz: ids } }); + mockDomainObject.getModel.and.returnValue({ relationships: { xyz: ids } }); relationship.getRelatedObjects('xyz'); @@ -95,7 +95,7 @@ define( }); it("provides a list of relationship types", function () { - mockDomainObject.getModel.andReturn({ relationships: { + mockDomainObject.getModel.and.returnValue({ relationships: { abc: ['a', 'b'], def: "not an array, should be ignored", xyz: [] @@ -107,14 +107,14 @@ define( // Lookups can be expensive, so this capability // should have some self-caching mockDomainObject.getModel - .andReturn({ relationships: { xyz: ['a'] } }); + .and.returnValue({ relationships: { xyz: ['a'] } }); // Call twice; response should be the same object instance expect(relationship.getRelatedObjects('xyz')) .toBe(relationship.getRelatedObjects('xyz')); // Should have only made one call - expect(mockObjectService.getObjects.calls.length) + expect(mockObjectService.getObjects.calls.count()) .toEqual(1); }); @@ -125,7 +125,7 @@ define( testModel = { relationships: { xyz: ['a'] } }; - mockDomainObject.getModel.andReturn(testModel); + mockDomainObject.getModel.and.returnValue(testModel); // Call twice, but as if modification had occurred in between relationship.getRelatedObjects('xyz'); @@ -133,7 +133,7 @@ define( relationship.getRelatedObjects('xyz'); // Should have only made one call - expect(mockObjectService.getObjects.calls.length) + expect(mockObjectService.getObjects.calls.count()) .toEqual(2); }); diff --git a/platform/core/test/models/CachingModelDecoratorSpec.js b/platform/core/test/models/CachingModelDecoratorSpec.js index 5739d00aa4..669279d0e0 100644 --- a/platform/core/test/models/CachingModelDecoratorSpec.js +++ b/platform/core/test/models/CachingModelDecoratorSpec.js @@ -67,7 +67,7 @@ define( a: { someKey: "some value" }, b: { someOtherKey: "some other value" } }; - mockModelService.getModels.andReturn(asPromise(testModels)); + mockModelService.getModels.and.returnValue(asPromise(testModels)); decorator = new CachingModelDecorator( new ModelCacheService(), mockModelService @@ -80,19 +80,19 @@ define( }); it("does not try to reload cached models", function () { - mockModelService.getModels.andReturn(asPromise({ a: testModels.a })); + mockModelService.getModels.and.returnValue(asPromise({ a: testModels.a })); decorator.getModels(['a']); - mockModelService.getModels.andReturn(asPromise(testModels)); + mockModelService.getModels.and.returnValue(asPromise(testModels)); decorator.getModels(['a', 'b']); expect(mockModelService.getModels).not.toHaveBeenCalledWith(['a', 'b']); - expect(mockModelService.getModels.mostRecentCall.args[0]).toEqual(['b']); + expect(mockModelService.getModels.calls.mostRecent().args[0]).toEqual(['b']); }); it("does not call its wrapped model service if not needed", function () { decorator.getModels(['a', 'b']); - expect(mockModelService.getModels.calls.length).toEqual(1); + expect(mockModelService.getModels.calls.count()).toEqual(1); decorator.getModels(['a', 'b']).then(mockCallback); - expect(mockModelService.getModels.calls.length).toEqual(1); + expect(mockModelService.getModels.calls.count()).toEqual(1); // Verify that we still got back our models, even though // no new call to the wrapped service was made expect(mockCallback).toHaveBeenCalledWith(testModels); @@ -105,9 +105,9 @@ define( promiseB = fakePromise(); // Issue two calls before those promises resolve - mockModelService.getModels.andReturn(promiseA); + mockModelService.getModels.and.returnValue(promiseA); decorator.getModels(['a']); - mockModelService.getModels.andReturn(promiseB); + mockModelService.getModels.and.returnValue(promiseB); decorator.getModels(['a']).then(mockCallback); // Then resolve those promises. Note that we're whiteboxing here @@ -119,9 +119,9 @@ define( }); // Ensure that we have a pointer-identical instance - expect(mockCallback.mostRecentCall.args[0].a) + expect(mockCallback.calls.mostRecent().args[0].a) .toEqual({ someNewKey: "some other value" }); - expect(mockCallback.mostRecentCall.args[0].a) + expect(mockCallback.calls.mostRecent().args[0].a) .toBe(testModels.a); }); @@ -132,9 +132,9 @@ define( promiseB = fakePromise(); // Issue two calls before those promises resolve - mockModelService.getModels.andReturn(promiseA); + mockModelService.getModels.and.returnValue(promiseA); decorator.getModels(['a']); - mockModelService.getModels.andReturn(promiseB); + mockModelService.getModels.and.returnValue(promiseB); decorator.getModels(['a']).then(mockCallback); // Some model providers might erroneously add undefined values @@ -147,7 +147,7 @@ define( }); // Should still have gotten the model - expect(mockCallback.mostRecentCall.args[0].a) + expect(mockCallback.calls.mostRecent().args[0].a) .toEqual({ someNewKey: "some other value" }); }); diff --git a/platform/core/test/models/MissingModelDecoratorSpec.js b/platform/core/test/models/MissingModelDecoratorSpec.js index 373f5f01af..1b62fa538c 100644 --- a/platform/core/test/models/MissingModelDecoratorSpec.js +++ b/platform/core/test/models/MissingModelDecoratorSpec.js @@ -47,7 +47,7 @@ define( testId: { someKey: "some value" } }; - mockModelService.getModels.andReturn(asPromise(testModels)); + mockModelService.getModels.and.returnValue(asPromise(testModels)); decorator = new MissingModelDecorator(mockModelService); }); diff --git a/platform/core/test/models/ModelAggregatorSpec.js b/platform/core/test/models/ModelAggregatorSpec.js index 6304882c51..49525fc09d 100644 --- a/platform/core/test/models/ModelAggregatorSpec.js +++ b/platform/core/test/models/ModelAggregatorSpec.js @@ -43,11 +43,11 @@ define( "mockProvider" + i, ["getModels"] ); - mockProvider.getModels.andReturn(models); + mockProvider.getModels.and.returnValue(models); return mockProvider; }); - mockQ.all.andReturn({ + mockQ.all.and.returnValue({ then: function (c) { return c(modelList); } diff --git a/platform/core/test/models/PersistedModelProviderSpec.js b/platform/core/test/models/PersistedModelProviderSpec.js index 03b954febf..c504518078 100644 --- a/platform/core/test/models/PersistedModelProviderSpec.js +++ b/platform/core/test/models/PersistedModelProviderSpec.js @@ -67,7 +67,7 @@ define( mockNow = jasmine.createSpy("now"); mockPersistenceService.readObject - .andCallFake(function (space, id) { + .and.callFake(function (space, id) { return mockPromise({ space: space, id: id, @@ -76,7 +76,7 @@ define( }); }); mockPersistenceService.listSpaces - .andReturn(mockPromise([SPACE])); + .and.returnValue(mockPromise([SPACE])); provider = new PersistedModelProvider( mockPersistenceService, @@ -94,9 +94,9 @@ define( }); expect(models).toEqual({ - a: { space: SPACE, id: "a", persisted: 0 }, - x: { space: SPACE, id: "x", persisted: 0 }, - zz: { space: SPACE, id: "zz", persisted: 0 } + a: { space: SPACE, id: "a", persisted: 0, modified: undefined }, + x: { space: SPACE, id: "x", persisted: 0, modified: undefined }, + zz: { space: SPACE, id: "zz", persisted: 0, modified: undefined } }); }); @@ -110,12 +110,12 @@ define( d: { name: "D" } }; - mockPersistenceService.readObject.andCallFake( + mockPersistenceService.readObject.and.callFake( function (space, id) { return mockPromise(testModels[id]); } ); - mockNow.andReturn(12321); + mockNow.and.returnValue(12321); provider.getModels(Object.keys(testModels)).then(mockCallback); diff --git a/platform/core/test/models/StaticModelProviderSpec.js b/platform/core/test/models/StaticModelProviderSpec.js index 37c79cacf0..1ded101f41 100644 --- a/platform/core/test/models/StaticModelProviderSpec.js +++ b/platform/core/test/models/StaticModelProviderSpec.js @@ -58,17 +58,17 @@ define( var mockPromise = { then: function () { return; } }; - mockQ.when.andReturn(mockPromise); + mockQ.when.and.returnValue(mockPromise); // Verify that we got the promise as the return value expect(provider.getModels(["a", "b"])).toEqual(mockPromise); // Verify that the promise has the desired models - expect(mockQ.when.callCount).toEqual(1); - expect(mockQ.when.mostRecentCall.args[0].a.name).toEqual("Thing A"); - expect(mockQ.when.mostRecentCall.args[0].a.someProperty).toEqual("Some Value A"); - expect(mockQ.when.mostRecentCall.args[0].b.name).toEqual("Thing B"); - expect(mockQ.when.mostRecentCall.args[0].b.someProperty).toEqual("Some Value B"); + expect(mockQ.when.calls.count()).toEqual(1); + expect(mockQ.when.calls.mostRecent().args[0].a.name).toEqual("Thing A"); + expect(mockQ.when.calls.mostRecent().args[0].a.someProperty).toEqual("Some Value A"); + expect(mockQ.when.calls.mostRecent().args[0].b.name).toEqual("Thing B"); + expect(mockQ.when.calls.mostRecent().args[0].b.someProperty).toEqual("Some Value B"); }); @@ -76,8 +76,8 @@ define( provider.getModels(["c"]); // Verify that the promise has the desired models - expect(mockQ.when.callCount).toEqual(1); - expect(mockQ.when.mostRecentCall.args[0].c).toBeUndefined(); + expect(mockQ.when.calls.count()).toEqual(1); + expect(mockQ.when.calls.mostRecent().args[0].c).toBeUndefined(); }); it("logs a warning when model definitions are malformed", function () { @@ -94,7 +94,7 @@ define( ], mockQ, mockLog)).toBeDefined(); // Should show warnings - expect(mockLog.warn.callCount).toEqual(5); + expect(mockLog.warn.calls.count()).toEqual(5); }); }); diff --git a/platform/core/test/objects/DomainObjectProviderSpec.js b/platform/core/test/objects/DomainObjectProviderSpec.js index 13f2466267..908aa1cffc 100644 --- a/platform/core/test/objects/DomainObjectProviderSpec.js +++ b/platform/core/test/objects/DomainObjectProviderSpec.js @@ -53,7 +53,7 @@ define( ); mockInstantiate = jasmine.createSpy("instantiate"); - mockInstantiate.andCallFake(function (model, id) { + mockInstantiate.and.callFake(function (model, id) { return new DomainObjectImpl(id, model, {}); }); @@ -65,7 +65,7 @@ define( it("requests models from the model service", function () { var ids = ["a", "b", "c"]; - mockModelService.getModels.andReturn(mockPromise({})); + mockModelService.getModels.and.returnValue(mockPromise({})); provider.getObjects(ids); expect(mockModelService.getModels).toHaveBeenCalledWith(ids); }); @@ -75,7 +75,7 @@ define( var ids = ["a", "b", "c"], model = { someKey: "some value"}, result; - mockModelService.getModels.andReturn(mockPromise({ a: model })); + mockModelService.getModels.and.returnValue(mockPromise({ a: model })); result = provider.getObjects(ids).testValue; expect(mockInstantiate).toHaveBeenCalledWith(model, 'a'); expect(result.a.getId()).toEqual("a"); diff --git a/platform/core/test/runs/TransactingMutationListenerSpec.js b/platform/core/test/runs/TransactingMutationListenerSpec.js index 240ccd51b6..139b0fa6dd 100644 --- a/platform/core/test/runs/TransactingMutationListenerSpec.js +++ b/platform/core/test/runs/TransactingMutationListenerSpec.js @@ -51,15 +51,15 @@ define( ['persist', 'refresh', 'persisted'] ); - mockTopic.andCallFake(function (t) { + mockTopic.and.callFake(function (t) { return (t === 'mutation') && mockMutationTopic; }); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return (c === 'persistence') && mockPersistence; }); - mockPersistence.persisted.andReturn(true); + mockPersistence.persisted.and.returnValue(true); return new TransactingMutationListener( mockTopic, @@ -83,12 +83,12 @@ define( var innerVerb = isActive ? "does" : "doesn't"; beforeEach(function () { - mockTransactionService.isActive.andReturn(isActive); + mockTransactionService.isActive.and.returnValue(isActive); }); describe("and mutation occurs", function () { beforeEach(function () { - mockMutationTopic.listen.mostRecentCall + mockMutationTopic.listen.calls.mostRecent() .args[0](mockDomainObject); }); diff --git a/platform/core/test/services/InstantiateSpec.js b/platform/core/test/services/InstantiateSpec.js index b8debf2aeb..344262dfa7 100644 --- a/platform/core/test/services/InstantiateSpec.js +++ b/platform/core/test/services/InstantiateSpec.js @@ -49,12 +49,12 @@ define( ); mockCapabilityConstructor = jasmine.createSpy('capability'); mockCapabilityInstance = {}; - mockCapabilityService.getCapabilities.andReturn({ + mockCapabilityService.getCapabilities.and.returnValue({ something: mockCapabilityConstructor }); - mockCapabilityConstructor.andReturn(mockCapabilityInstance); + mockCapabilityConstructor.and.returnValue(mockCapabilityInstance); - mockIdentifierService.generate.andCallFake(function (space) { + mockIdentifierService.generate.and.callFake(function (space) { return (space ? (space + ":") : "") + "some-id-" + (idCounter += 1); }); diff --git a/platform/core/test/services/ThrottleSpec.js b/platform/core/test/services/ThrottleSpec.js index 6f91e72b55..5f4d4675db 100644 --- a/platform/core/test/services/ThrottleSpec.js +++ b/platform/core/test/services/ThrottleSpec.js @@ -34,7 +34,7 @@ define( mockTimeout = jasmine.createSpy("$timeout"); mockPromise = jasmine.createSpyObj("promise", ["then"]); mockFn = jasmine.createSpy("fn"); - mockTimeout.andReturn(mockPromise); + mockTimeout.and.returnValue(mockPromise); throttle = new Throttle(mockTimeout); }); @@ -53,18 +53,18 @@ define( throttled(); throttled(); throttled(); - expect(mockTimeout.calls.length).toEqual(1); + expect(mockTimeout.calls.count()).toEqual(1); }); it("schedules additional invocations after resolution", function () { var throttled = throttle(mockFn); throttled(); - mockTimeout.mostRecentCall.args[0](); // Resolve timeout + mockTimeout.calls.mostRecent().args[0](); // Resolve timeout throttled(); - mockTimeout.mostRecentCall.args[0](); + mockTimeout.calls.mostRecent().args[0](); throttled(); - mockTimeout.mostRecentCall.args[0](); - expect(mockTimeout.calls.length).toEqual(3); + mockTimeout.calls.mostRecent().args[0](); + expect(mockTimeout.calls.count()).toEqual(3); }); }); } diff --git a/platform/core/test/services/TopicSpec.js b/platform/core/test/services/TopicSpec.js index 36e20ec16c..6bc390b15c 100644 --- a/platform/core/test/services/TopicSpec.js +++ b/platform/core/test/services/TopicSpec.js @@ -72,7 +72,7 @@ define( var mockBadCallback = jasmine.createSpy("bad-callback"), t = topic(); - mockBadCallback.andCallFake(function () { + mockBadCallback.and.callFake(function () { throw new Error("I'm afraid I can't do that."); }); diff --git a/platform/core/test/types/TypeCapabilitySpec.js b/platform/core/test/types/TypeCapabilitySpec.js index 8d5fae8a7c..82695cd635 100644 --- a/platform/core/test/types/TypeCapabilitySpec.js +++ b/platform/core/test/types/TypeCapabilitySpec.js @@ -42,16 +42,22 @@ define( "domainObject", ["getId", "getModel", "getCapability"] ); - mockType = { someKey: "some value" }; + mockType = { + someKey: "some value", + someOtherProperty: "some other property", + aThirdProperty: "a third property" + }; - mockTypeService.getType.andReturn(mockType); - mockDomainObject.getModel.andReturn({type: "mockType"}); + mockTypeService.getType.and.returnValue(mockType); + mockDomainObject.getModel.and.returnValue({type: "mockType"}); type = new TypeCapability(mockTypeService, mockDomainObject); }); it("looks up an object's type from type service", function () { - expect(type).toEqual(mockType); + expect(type.someKey).toEqual(mockType.someKey); + expect(type.someOtherProperty).toEqual(mockType.someOtherProperty); + expect(type.aThirdProperty).toEqual(mockType.aThirdProperty); expect(mockTypeService.getType).toHaveBeenCalledWith("mockType"); }); diff --git a/platform/core/test/views/ViewCapabilitySpec.js b/platform/core/test/views/ViewCapabilitySpec.js index 99c530920a..0853d713b5 100644 --- a/platform/core/test/views/ViewCapabilitySpec.js +++ b/platform/core/test/views/ViewCapabilitySpec.js @@ -42,7 +42,7 @@ define( "domainObject", ["getId", "getModel", "getCapability"] ); - mockViewService.getViews.andReturn(views); + mockViewService.getViews.and.returnValue(views); view = new ViewCapability(mockViewService, mockDomainObject); }); diff --git a/platform/core/test/views/ViewProviderSpec.js b/platform/core/test/views/ViewProviderSpec.js index 1387d96a74..2f9e58e709 100644 --- a/platform/core/test/views/ViewProviderSpec.js +++ b/platform/core/test/views/ViewProviderSpec.js @@ -116,17 +116,17 @@ define( "type", ["instanceOf", "invoke", "getDefinition"] ); - capabilities.type.invoke.andReturn(capabilities.type); + capabilities.type.invoke.and.returnValue(capabilities.type); // Should be included when types match - capabilities.type.instanceOf.andReturn(true); + capabilities.type.instanceOf.and.returnValue(true); expect(viewProvider.getViews(mockDomainObject)) .toEqual([testView]); expect(capabilities.type.instanceOf) .toHaveBeenCalledWith(testType); // ...but not when they don't - capabilities.type.instanceOf.andReturn(false); + capabilities.type.instanceOf.and.returnValue(false); expect(viewProvider.getViews(mockDomainObject)) .toEqual([]); @@ -141,17 +141,17 @@ define( "type", ["instanceOf", "invoke", "getDefinition"] ); - capabilities.type.invoke.andReturn(capabilities.type); + capabilities.type.invoke.and.returnValue(capabilities.type); // Should be included when view keys match capabilities.type.getDefinition - .andReturn({ views: [testView.key]}); + .and.returnValue({ views: [testView.key]}); expect(viewProvider.getViews(mockDomainObject)) .toEqual([testView]); // ...but not when they don't capabilities.type.getDefinition - .andReturn({ views: ["somethingElse"]}); + .and.returnValue({ views: ["somethingElse"]}); expect(viewProvider.getViews(mockDomainObject)) .toEqual([]); }); diff --git a/platform/entanglement/test/ControlledPromise.js b/platform/entanglement/test/ControlledPromise.js index 505c78806f..3b3c39fd51 100644 --- a/platform/entanglement/test/ControlledPromise.js +++ b/platform/entanglement/test/ControlledPromise.js @@ -31,7 +31,7 @@ define( function ControlledPromise() { this.resolveHandlers = []; this.rejectHandlers = []; - spyOn(this, 'then').andCallThrough(); + spyOn(this, 'then').and.callThrough(); } diff --git a/platform/entanglement/test/DomainObjectFactory.js b/platform/entanglement/test/DomainObjectFactory.js index abae9b6624..4c45433844 100644 --- a/platform/entanglement/test/DomainObjectFactory.js +++ b/platform/entanglement/test/DomainObjectFactory.js @@ -85,7 +85,7 @@ define( * * @returns {string} id */ - domainObject.getId.andCallFake(function () { + domainObject.getId.and.callFake(function () { return domainObject.id; }); @@ -94,7 +94,7 @@ define( * * @returns {object} model */ - domainObject.getModel.andCallFake(function () { + domainObject.getModel.and.callFake(function () { return domainObject.model; }); @@ -106,7 +106,7 @@ define( * @param {string} capability name of the capability to return. * @returns {*} capability object */ - domainObject.getCapability.andCallFake(function (capability) { + domainObject.getCapability.and.callFake(function (capability) { if (config.capabilities.hasOwnProperty(capability)) { return config.capabilities[capability]; } @@ -120,7 +120,7 @@ define( * existence of. * @returns {boolean} */ - domainObject.hasCapability.andCallFake(function (capability) { + domainObject.hasCapability.and.callFake(function (capability) { return config.capabilities.hasOwnProperty(capability); }); @@ -133,7 +133,7 @@ define( * @param {...*} params to pass to the capability's `invoke` method. * @returns {*} result whatever was returned by `invoke`. */ - domainObject.useCapability.andCallFake(function (capability) { + domainObject.useCapability.and.callFake(function (capability) { if (config.capabilities.hasOwnProperty(capability)) { if (!config.capabilities[capability].invoke) { throw new Error( diff --git a/platform/entanglement/test/actions/AbstractComposeActionSpec.js b/platform/entanglement/test/actions/AbstractComposeActionSpec.js index b7001824f4..e5895ecd81 100644 --- a/platform/entanglement/test/actions/AbstractComposeActionSpec.js +++ b/platform/entanglement/test/actions/AbstractComposeActionSpec.js @@ -71,7 +71,7 @@ define( selectedObjectContextCapability .getParent - .andReturn(currentParent); + .and.returnValue(currentParent); newParent = domainObjectFactory({ name: 'newParent' @@ -91,11 +91,11 @@ define( ] ); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); locationService .getLocationFromUser - .andReturn(locationServicePromise); + .and.returnValue(locationServicePromise); composeService = new MockCopyService(); }); @@ -165,7 +165,7 @@ define( it("copies object to selected location", function () { locationServicePromise .then - .mostRecentCall + .calls.mostRecent() .args[0](newParent); expect(composeService.perform) @@ -177,20 +177,20 @@ define( beforeEach(function () { validator = locationService.getLocationFromUser - .mostRecentCall.args[2]; - composeService.validate.andReturn(true); - policyService.allow.andReturn(true); + .calls.mostRecent().args[2]; + composeService.validate.and.returnValue(true); + policyService.allow.and.returnValue(true); }); it("is sensitive to policy", function () { expect(validator()).toBe(true); - policyService.allow.andReturn(false); + policyService.allow.and.returnValue(false); expect(validator()).toBe(false); }); it("is sensitive to service-specific validation", function () { expect(validator()).toBe(true); - composeService.validate.andReturn(false); + composeService.validate.and.returnValue(false); expect(validator()).toBe(false); }); diff --git a/platform/entanglement/test/actions/CopyActionSpec.js b/platform/entanglement/test/actions/CopyActionSpec.js index 0330fae052..2a28fcae0e 100644 --- a/platform/entanglement/test/actions/CopyActionSpec.js +++ b/platform/entanglement/test/actions/CopyActionSpec.js @@ -55,7 +55,7 @@ define( 'policyService', ['allow'] ); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); selectedObjectContextCapability = jasmine.createSpyObj( 'selectedObjectContextCapability', @@ -80,7 +80,7 @@ define( selectedObjectContextCapability .getParent - .andReturn(currentParent); + .and.returnValue(currentParent); newParent = domainObjectFactory({ name: 'newParent' @@ -107,26 +107,26 @@ define( ] ); - abstractComposePromise.then.andCallFake(function (success, error, notify) { + abstractComposePromise.then.and.callFake(function (success, error, notify) { notify(progress); success(domainObject); }); - locationServicePromise.then.andCallFake(function (callback) { + locationServicePromise.then.and.callFake(function (callback) { callback(newParent); return abstractComposePromise; }); locationService .getLocationFromUser - .andReturn(locationServicePromise); + .and.returnValue(locationServicePromise); dialogService = jasmine.createSpyObj('dialogService', ['showBlockingMessage'] ); mockDialog = jasmine.createSpyObj("dialog", ["dismiss"]); - dialogService.showBlockingMessage.andReturn(mockDialog); + dialogService.showBlockingMessage.and.returnValue(mockDialog); notification = jasmine.createSpyObj('notification', ['dismiss', 'model'] @@ -136,7 +136,7 @@ define( ['notify', 'info'] ); - notificationService.notify.andReturn(notification); + notificationService.notify.and.returnValue(notification); mockLog = jasmine.createSpyObj('log', ['error']); @@ -167,7 +167,7 @@ define( describe("when performed it", function () { beforeEach(function () { - spyOn(copyAction, 'progress').andCallThrough(); + spyOn(copyAction, 'progress').and.callThrough(); copyAction.perform(); }); @@ -189,7 +189,7 @@ define( it("copies object to selected location", function () { locationServicePromise .then - .mostRecentCall + .calls.mostRecent() .args[0](newParent); expect(copyService.perform) diff --git a/platform/entanglement/test/actions/GoToOriginalActionSpec.js b/platform/entanglement/test/actions/GoToOriginalActionSpec.js index a0f2c98827..18188198a7 100644 --- a/platform/entanglement/test/actions/GoToOriginalActionSpec.js +++ b/platform/entanglement/test/actions/GoToOriginalActionSpec.js @@ -47,9 +47,9 @@ define( ['perform', 'getActions'] ); originalPromise = new ControlledPromise(); - mockLocationCapability.getOriginal.andReturn(originalPromise); - mockLocationCapability.isLink.andReturn(true); - mockLocationCapability.isOriginal.andCallFake(function () { + mockLocationCapability.getOriginal.and.returnValue(originalPromise); + mockLocationCapability.isLink.and.returnValue(true); + mockLocationCapability.isOriginal.and.callFake(function () { return !mockLocationCapability.isLink(); }); testContext = { @@ -74,7 +74,7 @@ define( }); it("is not applicable to originals", function () { - mockLocationCapability.isLink.andReturn(false); + mockLocationCapability.isLink.and.returnValue(false); expect(GoToOriginalAction.appliesTo(testContext)) .toBeFalsy(); }); diff --git a/platform/entanglement/test/actions/LinkActionSpec.js b/platform/entanglement/test/actions/LinkActionSpec.js index e62bf79cb7..3d457eada1 100644 --- a/platform/entanglement/test/actions/LinkActionSpec.js +++ b/platform/entanglement/test/actions/LinkActionSpec.js @@ -47,7 +47,7 @@ define( 'policyService', ['allow'] ); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); selectedObjectContextCapability = jasmine.createSpyObj( 'selectedObjectContextCapability', @@ -72,7 +72,7 @@ define( selectedObjectContextCapability .getParent - .andReturn(currentParent); + .and.returnValue(currentParent); newParent = domainObjectFactory({ name: 'newParent' @@ -94,7 +94,7 @@ define( locationService .getLocationFromUser - .andReturn(locationServicePromise); + .and.returnValue(locationServicePromise); linkService = new MockLinkService(); }); @@ -141,7 +141,7 @@ define( it("links object to selected location", function () { locationServicePromise .then - .mostRecentCall + .calls.mostRecent() .args[0](newParent); expect(linkService.perform) diff --git a/platform/entanglement/test/actions/MoveActionSpec.js b/platform/entanglement/test/actions/MoveActionSpec.js index 955599e97e..8303820c21 100644 --- a/platform/entanglement/test/actions/MoveActionSpec.js +++ b/platform/entanglement/test/actions/MoveActionSpec.js @@ -47,7 +47,7 @@ define( 'policyService', ['allow'] ); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); selectedObjectContextCapability = jasmine.createSpyObj( 'selectedObjectContextCapability', @@ -72,7 +72,7 @@ define( selectedObjectContextCapability .getParent - .andReturn(currentParent); + .and.returnValue(currentParent); newParent = domainObjectFactory({ name: 'newParent' @@ -94,7 +94,7 @@ define( locationService .getLocationFromUser - .andReturn(locationServicePromise); + .and.returnValue(locationServicePromise); moveService = new MockMoveService(); }); @@ -141,7 +141,7 @@ define( it("moves object to selected location", function () { locationServicePromise .then - .mostRecentCall + .calls.mostRecent() .args[0](newParent); expect(moveService.perform) diff --git a/platform/entanglement/test/actions/SetPrimaryLocationActionSpec.js b/platform/entanglement/test/actions/SetPrimaryLocationActionSpec.js index 5eba177b93..5c4cff84e8 100644 --- a/platform/entanglement/test/actions/SetPrimaryLocationActionSpec.js +++ b/platform/entanglement/test/actions/SetPrimaryLocationActionSpec.js @@ -43,7 +43,7 @@ define( ['setPrimaryLocation', 'getContextualLocation'] ); - mockLocationCapability.getContextualLocation.andReturn(testId); + mockLocationCapability.getContextualLocation.and.returnValue(testId); testContext = { domainObject: domainObjectFactory({ @@ -58,7 +58,7 @@ define( it("is applicable to objects with no location specified", function () { expect(SetPrimaryLocation.appliesTo(testContext)) .toBe(true); - testContext.domainObject.getModel.andReturn({ + testContext.domainObject.getModel.and.returnValue({ location: "something", name: "some name" }); diff --git a/platform/entanglement/test/capabilities/LocationCapabilitySpec.js b/platform/entanglement/test/capabilities/LocationCapabilitySpec.js index f62e638360..118c61d335 100644 --- a/platform/entanglement/test/capabilities/LocationCapabilitySpec.js +++ b/platform/entanglement/test/capabilities/LocationCapabilitySpec.js @@ -61,7 +61,7 @@ define( jasmine.createSpyObj("objectService", ["getObjects"]); mutationPromise = new ControlledPromise(); - domainObject.capabilities.mutation.invoke.andCallFake( + domainObject.capabilities.mutation.invoke.and.callFake( function (mutator) { return mutationPromise.then(function () { mutator(domainObject.model); @@ -114,10 +114,10 @@ define( mockCallback; function resolvePromises() { - if (mockQ.when.calls.length > 0) { - qPromise.resolve(mockQ.when.mostRecentCall.args[0]); + if (mockQ.when.calls.count() > 0) { + qPromise.resolve(mockQ.when.calls.mostRecent().args[0]); } - if (mockObjectService.getObjects.calls.length > 0) { + if (mockObjectService.getObjects.calls.count() > 0) { objectPromise.resolve(originalObjects); } } @@ -129,11 +129,11 @@ define( testObject: domainObjectFactory() }; - mockInjector.get.andCallFake(function (key) { + mockInjector.get.and.callFake(function (key) { return key === 'objectService' && mockObjectService; }); - mockObjectService.getObjects.andReturn(objectPromise); - mockQ.when.andReturn(qPromise); + mockObjectService.getObjects.and.returnValue(objectPromise); + mockQ.when.and.returnValue(qPromise); mockCallback = jasmine.createSpy('callback'); }); diff --git a/platform/entanglement/test/policies/CopyPolicySpec.js b/platform/entanglement/test/policies/CopyPolicySpec.js index 2c9dc3c76b..1ebd3e6a74 100644 --- a/platform/entanglement/test/policies/CopyPolicySpec.js +++ b/platform/entanglement/test/policies/CopyPolicySpec.js @@ -43,12 +43,12 @@ define([ capabilities: { type: mockType } }); - mockType.hasFeature.andCallFake(function (feature) { + mockType.hasFeature.and.callFake(function (feature) { return feature === 'creation'; }); mockAction = jasmine.createSpyObj('action', ['getMetadata']); - mockAction.getMetadata.andReturn(testMetadata); + mockAction.getMetadata.and.returnValue(testMetadata); testContext = { domainObject: mockDomainObject }; @@ -62,7 +62,7 @@ define([ describe("when an object is non-creatable", function () { beforeEach(function () { - mockType.hasFeature.andReturn(false); + mockType.hasFeature.and.returnValue(false); }); it("disallows the action", function () { @@ -84,7 +84,7 @@ define([ it("simply allows the action", function () { expect(policy.allow(mockAction, testContext)).toBe(true); - mockType.hasFeature.andReturn(false); + mockType.hasFeature.and.returnValue(false); expect(policy.allow(mockAction, testContext)).toBe(true); }); }); diff --git a/platform/entanglement/test/policies/CrossSpacePolicySpec.js b/platform/entanglement/test/policies/CrossSpacePolicySpec.js index 48b8871079..71d2eead73 100644 --- a/platform/entanglement/test/policies/CrossSpacePolicySpec.js +++ b/platform/entanglement/test/policies/CrossSpacePolicySpec.js @@ -39,7 +39,7 @@ define( 'persistence', ['getSpace'] ); - mockPersistence.getSpace.andReturn(space); + mockPersistence.getSpace.and.returnValue(space); return domainObjectFactory({ id: space + ":foo", model: {}, @@ -56,7 +56,7 @@ define( 'action', ['getMetadata'] ); - mockAction.getMetadata.andReturn(testActionMetadata); + mockAction.getMetadata.and.returnValue(testActionMetadata); sameSpaceContext = { domainObject: makeObject('a'), diff --git a/platform/entanglement/test/policies/MovePolicySpec.js b/platform/entanglement/test/policies/MovePolicySpec.js index 3c337d4f3c..75107acf65 100644 --- a/platform/entanglement/test/policies/MovePolicySpec.js +++ b/platform/entanglement/test/policies/MovePolicySpec.js @@ -59,17 +59,17 @@ define([ } }); - mockContextCapability.getParent.andReturn(mockParent); + mockContextCapability.getParent.and.returnValue(mockParent); - mockType.hasFeature.andCallFake(function (feature) { + mockType.hasFeature.and.callFake(function (feature) { return feature === 'creation'; }); - mockParentType.hasFeature.andCallFake(function (feature) { + mockParentType.hasFeature.and.callFake(function (feature) { return feature === 'creation'; }); mockAction = jasmine.createSpyObj('action', ['getMetadata']); - mockAction.getMetadata.andReturn(testMetadata); + mockAction.getMetadata.and.returnValue(testMetadata); testContext = { domainObject: mockDomainObject }; @@ -83,7 +83,7 @@ define([ describe("when an object is non-modifiable", function () { beforeEach(function () { - mockType.hasFeature.andReturn(false); + mockType.hasFeature.and.returnValue(false); }); it("disallows the action", function () { @@ -93,7 +93,7 @@ define([ describe("when a parent is non-modifiable", function () { beforeEach(function () { - mockParentType.hasFeature.andReturn(false); + mockParentType.hasFeature.and.returnValue(false); }); it("disallows the action", function () { @@ -115,9 +115,9 @@ define([ it("simply allows the action", function () { expect(policy.allow(mockAction, testContext)).toBe(true); - mockType.hasFeature.andReturn(false); + mockType.hasFeature.and.returnValue(false); expect(policy.allow(mockAction, testContext)).toBe(true); - mockParentType.hasFeature.andReturn(false); + mockParentType.hasFeature.and.returnValue(false); expect(policy.allow(mockAction, testContext)).toBe(true); }); }); diff --git a/platform/entanglement/test/services/CopyServiceSpec.js b/platform/entanglement/test/services/CopyServiceSpec.js index 9de0131c8b..97bda1af8c 100644 --- a/platform/entanglement/test/services/CopyServiceSpec.js +++ b/platform/entanglement/test/services/CopyServiceSpec.js @@ -38,7 +38,7 @@ define( return synchronousPromise(callback(value)); } }; - spyOn(promise, 'then').andCallThrough(); + spyOn(promise, 'then').and.callThrough(); return promise; } @@ -109,12 +109,12 @@ define( }); it("and returns false", function () { - policyService.allow.andReturn(false); + policyService.allow.and.returnValue(false); expect(validate()).toBe(false); }); it("and returns true", function () { - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); expect(validate()).toBe(true); }); }); @@ -139,7 +139,7 @@ define( beforeEach(function () { createObjectPromise = synchronousPromise(undefined); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); persistObjectPromise = synchronousPromise(undefined); @@ -152,26 +152,26 @@ define( "persistenceCapability", ["persist", "getSpace"] ); - persistenceCapability.persist.andReturn(persistObjectPromise); + persistenceCapability.persist.and.returnValue(persistObjectPromise); compositionCapability = jasmine.createSpyObj( 'compositionCapability', ['invoke', 'add'] ); - compositionCapability.add.andCallFake(synchronousPromise); + compositionCapability.add.and.callFake(synchronousPromise); locationCapability = jasmine.createSpyObj( 'locationCapability', ['isLink'] ); - locationCapability.isLink.andReturn(false); + locationCapability.isLink.and.returnValue(false); mockDeferred = jasmine.createSpyObj( 'mockDeferred', ['notify', 'resolve', 'reject'] ); - mockDeferred.notify.andCallFake(function () {}); - mockDeferred.resolve.andCallFake(function (value) { + mockDeferred.notify.and.callFake(function () {}); + mockDeferred.resolve.and.callFake(function (value) { resolvedValue = value; }); mockDeferred.promise = { @@ -184,9 +184,9 @@ define( 'mockQ', ['when', 'all', 'reject', 'defer'] ); - mockQ.reject.andReturn(synchronousPromise(undefined)); - mockQ.when.andCallFake(synchronousPromise); - mockQ.all.andCallFake(function (promises) { + mockQ.reject.and.returnValue(synchronousPromise(undefined)); + mockQ.when.and.callFake(synchronousPromise); + mockQ.all.and.callFake(function (promises) { var result = {}; Object.keys(promises).forEach(function (k) { promises[k].then(function (v) { @@ -195,7 +195,7 @@ define( }); return synchronousPromise(result); }); - mockQ.defer.andReturn(mockDeferred); + mockQ.defer.and.returnValue(mockDeferred); }); @@ -241,7 +241,7 @@ define( } }); - instantiationCapability.invoke.andCallFake( + instantiationCapability.invoke.and.callFake( function (model) { objectCopy.model = model; return objectCopy; @@ -260,7 +260,7 @@ define( }); it("deep clones object model", function () { - var newModel = copyFinished.calls[0].args[0].getModel(); + var newModel = copyFinished.calls.all()[0].args[0].getModel(); expect(newModel).toEqual(object.model); expect(newModel).not.toBe(object.model); }); @@ -282,7 +282,7 @@ define( var invocationCount = 0, objectClones; - instantiationCapability.invoke.andCallFake( + instantiationCapability.invoke.and.callFake( function (model) { var cloneToReturn = objectClones[invocationCount++]; cloneToReturn.model = model; @@ -332,7 +332,7 @@ define( compositionCapability .invoke - .andReturn(synchronousPromise([childObject])); + .and.returnValue(synchronousPromise([childObject])); object = domainObjectFactory({ name: 'some object', @@ -390,7 +390,7 @@ define( describe("when cloning non-creatable objects", function () { beforeEach(function () { - policyService.allow.andCallFake(function (category) { + policyService.allow.and.callFake(function (category) { //Return false for 'creation' policy return category !== 'creation'; }); @@ -400,7 +400,7 @@ define( copyResult.then(copyFinished); }); it ("creates link instead of clone", function () { - var copiedObject = copyFinished.calls[0].args[0]; + var copiedObject = copyFinished.calls.all()[0].args[0]; expect(copiedObject).toBe(object); expect(compositionCapability.add) .toHaveBeenCalledWith(copiedObject); @@ -408,6 +408,10 @@ define( }); describe("when provided a filtering function", function () { + beforeEach(function () { + copyFinished = jasmine.createSpy('copyFinished'); + }); + function accept() { return true; } @@ -419,7 +423,7 @@ define( "rejected by the filter", function () { copyService.perform(object, newParent, reject) .then(copyFinished); - expect(copyFinished.mostRecentCall.args[0]) + expect(copyFinished.calls.mostRecent().args[0]) .toBe(object); }); @@ -427,7 +431,7 @@ define( "accepted by the filter", function () { copyService.perform(object, newParent, accept) .then(copyFinished); - expect(copyFinished.mostRecentCall.args[0]) + expect(copyFinished.calls.mostRecent().args[0]) .not.toBe(object); }); }); @@ -454,7 +458,7 @@ define( } }); - instantiationCapability.invoke.andReturn(object); + instantiationCapability.invoke.and.returnValue(object); }); it("throws an error", function () { @@ -466,9 +470,9 @@ define( } spyOn(service, "validate"); - service.validate.andReturn(true); + service.validate.and.returnValue(true); expect(perform).not.toThrow(); - service.validate.andReturn(false); + service.validate.and.returnValue(false); expect(perform).toThrow(); }); }); diff --git a/platform/entanglement/test/services/CopyTaskSpec.js b/platform/entanglement/test/services/CopyTaskSpec.js index 7d5429fc83..5cd5c54162 100644 --- a/platform/entanglement/test/services/CopyTaskSpec.js +++ b/platform/entanglement/test/services/CopyTaskSpec.js @@ -74,14 +74,14 @@ define( }); mockCapabilities.persistence.persist - .andReturn(synchronousPromise(true)); - mockCapabilities.composition.add.andCallFake(function (obj) { + .and.returnValue(synchronousPromise(true)); + mockCapabilities.composition.add.and.callFake(function (obj) { return synchronousPromise(obj); }); mockCapabilities.composition.invoke - .andReturn(synchronousPromise(mockChildren)); + .and.returnValue(synchronousPromise(mockChildren)); mockCapabilities.instantiation.invoke - .andCallFake(function (model) { + .and.callFake(function (model) { var id = "some-id-" + counter; cloneIds[model.originalId] = id; counter += 1; @@ -123,11 +123,11 @@ define( ['notify', 'resolve', 'reject'] ); - mockFilter.andReturn(true); + mockFilter.and.returnValue(true); - mockQ.when.andCallFake(synchronousPromise); - mockQ.defer.andReturn(mockDeferred); - mockQ.all.andCallFake(function (promises) { + mockQ.when.and.callFake(synchronousPromise); + mockQ.defer.and.returnValue(mockDeferred); + mockQ.all.and.callFake(function (promises) { return synchronousPromise(promises.map(function (promise) { var value; promise.then(function (v) { @@ -137,7 +137,7 @@ define( })); }); - mockDeferred.resolve.andCallFake(function (value) { + mockDeferred.resolve.and.callFake(function (value) { mockDeferred.promise = synchronousPromise(value); }); @@ -209,7 +209,7 @@ define( model: composingObjectModel }); - mockComposingObject.capabilities.composition.invoke.andReturn([mockDomainObject, mockDomainObjectB]); + mockComposingObject.capabilities.composition.invoke.and.returnValue([mockDomainObject, mockDomainObjectB]); task = new CopyTask( mockComposingObject, mockParentObject, @@ -235,13 +235,13 @@ define( childC_ID = task.clones[3].getId(), childD_ID = task.clones[4].getId(); - expect(domainObjectClone.model.someArr[0]).toNotBe(domainObjectBClone.model.someArr[0]); + expect(domainObjectClone.model.someArr[0]).not.toBe(domainObjectBClone.model.someArr[0]); expect(domainObjectClone.model.someArr[0]).toBe(childA_ID); expect(domainObjectBClone.model.someArr[0]).toBe(childC_ID); - expect(domainObjectClone.model.someArr[1]).toNotBe(domainObjectBClone.model.someArr[1]); + expect(domainObjectClone.model.someArr[1]).not.toBe(domainObjectBClone.model.someArr[1]); expect(domainObjectClone.model.someArr[1]).toBe(childB_ID); expect(domainObjectBClone.model.someArr[1]).toBe(childD_ID); - expect(domainObjectClone.model.someObj.someProperty).toNotBe(domainObjectBClone.model.someObj.someProperty); + expect(domainObjectClone.model.someObj.someProperty).not.toBe(domainObjectBClone.model.someObj.someProperty); expect(domainObjectClone.model.someObj.someProperty).toBe(childB_ID); expect(domainObjectBClone.model.someObj.someProperty).toBe(childD_ID); diff --git a/platform/entanglement/test/services/LinkServiceSpec.js b/platform/entanglement/test/services/LinkServiceSpec.js index 9fede61be7..d24e4eb576 100644 --- a/platform/entanglement/test/services/LinkServiceSpec.js +++ b/platform/entanglement/test/services/LinkServiceSpec.js @@ -39,7 +39,7 @@ define( 'policyService', ['allow'] ); - mockPolicyService.allow.andReturn(true); + mockPolicyService.allow.and.returnValue(true); linkService = new LinkService(mockPolicyService); }); @@ -92,7 +92,7 @@ define( }); object.id = 'abc'; parentCandidate.id = 'xyz'; - parentCandidate.hasCapability.andCallFake(function (c) { + parentCandidate.hasCapability.and.callFake(function (c) { return c !== 'composition'; }); expect(validate()).toBe(false); @@ -119,13 +119,13 @@ define( }); it("and returns false", function () { - mockPolicyService.allow.andReturn(true); + mockPolicyService.allow.and.returnValue(true); expect(validate()).toBe(true); expect(mockPolicyService.allow).toHaveBeenCalled(); }); it("and returns true", function () { - mockPolicyService.allow.andReturn(false); + mockPolicyService.allow.and.returnValue(false); expect(validate()).toBe(false); expect(mockPolicyService.allow).toHaveBeenCalled(); }); @@ -149,8 +149,8 @@ define( 'compositionCapability', ['invoke', 'add'] ); - compositionCapability.invoke.andReturn(compositionPromise); - compositionCapability.add.andReturn(addPromise); + compositionCapability.invoke.and.returnValue(compositionPromise); + compositionCapability.add.and.returnValue(addPromise); parentModel = { composition: [] }; @@ -205,9 +205,9 @@ define( } spyOn(linkService, 'validate'); - linkService.validate.andReturn(true); + linkService.validate.and.returnValue(true); expect(perform).not.toThrow(); - linkService.validate.andReturn(false); + linkService.validate.and.returnValue(false); expect(perform).toThrow(); }); }); diff --git a/platform/entanglement/test/services/LocatingCreationDecoratorSpec.js b/platform/entanglement/test/services/LocatingCreationDecoratorSpec.js index 957eb4f8bb..0b5023ea8b 100644 --- a/platform/entanglement/test/services/LocatingCreationDecoratorSpec.js +++ b/platform/entanglement/test/services/LocatingCreationDecoratorSpec.js @@ -46,8 +46,8 @@ define( 'domainObject', ['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability'] ); - mockCreationService.createObject.andReturn(mockPromise); - mockParent.getId.andReturn('test-id'); + mockCreationService.createObject.and.returnValue(mockPromise); + mockParent.getId.and.returnValue('test-id'); decorator = new LocatingCreationDecorator(mockCreationService); }); diff --git a/platform/entanglement/test/services/LocatingObjectDecoratorSpec.js b/platform/entanglement/test/services/LocatingObjectDecoratorSpec.js index d4df716193..bbaceee3ac 100644 --- a/platform/entanglement/test/services/LocatingObjectDecoratorSpec.js +++ b/platform/entanglement/test/services/LocatingObjectDecoratorSpec.js @@ -63,8 +63,8 @@ define( mockObjectService = jasmine.createSpyObj("objectService", ["getObjects"]); - mockQ.when.andCallFake(testPromise); - mockQ.all.andCallFake(function (promises) { + mockQ.when.and.callFake(testPromise); + mockQ.all.and.callFake(function (promises) { var result = {}; Object.keys(promises).forEach(function (k) { promises[k].then(function (v) { @@ -74,7 +74,7 @@ define( return testPromise(result); }); - mockObjectService.getObjects.andReturn(testPromise(testObjects)); + mockObjectService.getObjects.and.returnValue(testPromise(testObjects)); mockCallback = jasmine.createSpy("callback"); @@ -83,8 +83,8 @@ define( "domainObject-" + id, ["getId", "getModel", "getCapability"] ); - testObjects[id].getId.andReturn(id); - testObjects[id].getModel.andReturn(testModels[id]); + testObjects[id].getId.and.returnValue(id); + testObjects[id].getModel.and.returnValue(testModels[id]); }); decorator = new LocatingObjectDecorator( @@ -98,7 +98,7 @@ define( decorator.getObjects(['b', 'c']).then(mockCallback); expect(mockCallback).toHaveBeenCalled(); - var callbackObj = mockCallback.mostRecentCall.args[0]; + var callbackObj = mockCallback.calls.mostRecent().args[0]; expect(testObjects.b.getCapability('context')).not.toBeDefined(); expect(testObjects.c.getCapability('context')).not.toBeDefined(); expect(callbackObj.b.getCapability('context')).toBeDefined(); diff --git a/platform/entanglement/test/services/LocationServiceSpec.js b/platform/entanglement/test/services/LocationServiceSpec.js index ce35103825..47ae9e30c9 100644 --- a/platform/entanglement/test/services/LocationServiceSpec.js +++ b/platform/entanglement/test/services/LocationServiceSpec.js @@ -46,8 +46,8 @@ define( 'chainedPromise', ['then'] ); - dialogServicePromise.then.andReturn(chainedPromise); - dialogService.getUserInput.andReturn(dialogServicePromise); + dialogServicePromise.then.and.returnValue(chainedPromise); + dialogService.getUserInput.and.returnValue(dialogServicePromise); locationService = new LocationService(dialogService); }); @@ -75,11 +75,11 @@ define( ); formStructure = dialogService .getUserInput - .mostRecentCall + .calls.mostRecent() .args[0]; formState = dialogService .getUserInput - .mostRecentCall + .calls.mostRecent() .args[1]; }); @@ -131,7 +131,7 @@ define( beforeEach(function () { resolver = - dialogServicePromise.then.mostRecentCall.args[0]; + dialogServicePromise.then.calls.mostRecent().args[0]; selectedLocation = { key: "i'm a location key" }; dialogResult = { diff --git a/platform/entanglement/test/services/MockCopyService.js b/platform/entanglement/test/services/MockCopyService.js index d61d8ae51d..1a7aaaf0df 100644 --- a/platform/entanglement/test/services/MockCopyService.js +++ b/platform/entanglement/test/services/MockCopyService.js @@ -37,7 +37,7 @@ define( * var copyService = new MockCopyService(); * * // validate is a standard jasmine spy. - * copyService.validate.andReturn(true); + * copyService.validate.and.returnValue(true); * var isValid = copyService.validate(object, parentCandidate); * expect(isValid).toBe(true); * @@ -45,7 +45,7 @@ define( * var whenCopied = jasmine.createSpy('whenCopied'); * copyService.perform(object, parentObject).then(whenCopied); * expect(whenCopied).not.toHaveBeenCalled(); - * copyService.perform.mostRecentCall.resolve('someArg'); + * copyService.perform.calls.mostRecent().resolve('someArg'); * expect(whenCopied).toHaveBeenCalledWith('someArg'); * ``` */ @@ -60,7 +60,7 @@ define( ] ); - mockCopyService.perform.andCallFake(function () { + mockCopyService.perform.and.callFake(function () { var performPromise, callExtensions, spy; @@ -73,7 +73,7 @@ define( callExtensions = { promise: performPromise, resolve: function (resolveWith) { - performPromise.then.calls.forEach(function (call) { + performPromise.then.calls.all().forEach(function (call) { call.args[0](resolveWith); }); } @@ -82,8 +82,8 @@ define( spy = this.perform; Object.keys(callExtensions).forEach(function (key) { - spy.mostRecentCall[key] = callExtensions[key]; - spy.calls[spy.calls.length - 1][key] = callExtensions[key]; + spy.calls.mostRecent()[key] = callExtensions[key]; + spy.calls.all()[spy.calls.count() - 1][key] = callExtensions[key]; }); return performPromise; diff --git a/platform/entanglement/test/services/MockLinkService.js b/platform/entanglement/test/services/MockLinkService.js index 2ee1eed416..7811d2d2d3 100644 --- a/platform/entanglement/test/services/MockLinkService.js +++ b/platform/entanglement/test/services/MockLinkService.js @@ -40,7 +40,7 @@ define( * var linkService = new MockLinkService(); * * // validate is a standard jasmine spy. - * linkService.validate.andReturn(true); + * linkService.validate.and.returnValue(true); * var isValid = linkService.validate(object, parentObject); * expect(isValid).toBe(true); * @@ -48,7 +48,7 @@ define( * var whenLinked = jasmine.createSpy('whenLinked'); * linkService.perform(object, parentObject).then(whenLinked); * expect(whenLinked).not.toHaveBeenCalled(); - * linkService.perform.mostRecentCall.promise.resolve('someArg'); + * linkService.perform.calls.mostRecent().promise.resolve('someArg'); * expect(whenLinked).toHaveBeenCalledWith('someArg'); * ``` */ @@ -63,11 +63,11 @@ define( ] ); - mockLinkService.perform.andCallFake(function (object) { + mockLinkService.perform.and.callFake(function (object) { var performPromise = new ControlledPromise(); - this.perform.mostRecentCall.promise = performPromise; - this.perform.calls[this.perform.calls.length - 1].promise = + this.perform.calls.mostRecent().promise = performPromise; + this.perform.calls.all()[this.perform.calls.count() - 1].promise = performPromise; return performPromise.then(function (overrideObject) { diff --git a/platform/entanglement/test/services/MockMoveService.js b/platform/entanglement/test/services/MockMoveService.js index 92af19ab23..38f2059ae9 100644 --- a/platform/entanglement/test/services/MockMoveService.js +++ b/platform/entanglement/test/services/MockMoveService.js @@ -37,7 +37,7 @@ define( * var moveService = new MockMoveService(); * * // validate is a standard jasmine spy. - * moveService.validate.andReturn(true); + * moveService.validate.and.returnValue(true); * var isValid = moveService.validate(object, parentCandidate); * expect(isValid).toBe(true); * @@ -45,7 +45,7 @@ define( * var whenCopied = jasmine.createSpy('whenCopied'); * moveService.perform(object, parentObject).then(whenCopied); * expect(whenCopied).not.toHaveBeenCalled(); - * moveService.perform.mostRecentCall.resolve('someArg'); + * moveService.perform.calls.mostRecent().resolve('someArg'); * expect(whenCopied).toHaveBeenCalledWith('someArg'); * ``` */ @@ -60,7 +60,7 @@ define( ] ); - mockMoveService.perform.andCallFake(function () { + mockMoveService.perform.and.callFake(function () { var performPromise, callExtensions, spy; @@ -73,7 +73,7 @@ define( callExtensions = { promise: performPromise, resolve: function (resolveWith) { - performPromise.then.calls.forEach(function (call) { + performPromise.then.calls.all().forEach(function (call) { call.args[0](resolveWith); }); } @@ -82,8 +82,8 @@ define( spy = this.perform; Object.keys(callExtensions).forEach(function (key) { - spy.mostRecentCall[key] = callExtensions[key]; - spy.calls[spy.calls.length - 1][key] = callExtensions[key]; + spy.calls.mostRecent()[key] = callExtensions[key]; + spy.calls.all()[spy.calls.count() - 1][key] = callExtensions[key]; }); return performPromise; diff --git a/platform/entanglement/test/services/MoveServiceSpec.js b/platform/entanglement/test/services/MoveServiceSpec.js index b1e5d5761d..7e1cdb1905 100644 --- a/platform/entanglement/test/services/MoveServiceSpec.js +++ b/platform/entanglement/test/services/MoveServiceSpec.js @@ -66,7 +66,7 @@ define( id: 'b' }); - objectContextCapability.getParent.andReturn(currentParent); + objectContextCapability.getParent.and.returnValue(currentParent); parentCandidate = domainObjectFactory({ name: 'parentCandidate', @@ -81,7 +81,7 @@ define( ['allow'] ); linkService = new MockLinkService(); - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); moveService = new MoveService(policyService, linkService); }); @@ -129,12 +129,12 @@ define( }); it("and returns false", function () { - policyService.allow.andReturn(false); + policyService.allow.and.returnValue(false); expect(validate()).toBe(false); }); it("and returns true", function () { - policyService.allow.andReturn(true); + policyService.allow.and.returnValue(true); expect(validate()).toBe(true); }); }); @@ -167,7 +167,7 @@ define( locationPromise = new ControlledPromise(); locationCapability.setPrimaryLocation - .andReturn(locationPromise); + .and.returnValue(locationPromise); object = domainObjectFactory({ name: 'object', @@ -190,7 +190,7 @@ define( }); it("waits for result of link", function () { - expect(linkService.perform.mostRecentCall.promise.then) + expect(linkService.perform.calls.mostRecent().promise.then) .toHaveBeenCalledWith(jasmine.any(Function)); }); @@ -200,18 +200,18 @@ define( } spyOn(moveService, "validate"); - moveService.validate.andReturn(true); + moveService.validate.and.returnValue(true); expect(perform).not.toThrow(); - moveService.validate.andReturn(false); + moveService.validate.and.returnValue(false); expect(perform).toThrow(); }); describe("when moving an original", function () { beforeEach(function () { locationCapability.getContextualLocation - .andReturn('new-location'); - locationCapability.isOriginal.andReturn(true); - linkService.perform.mostRecentCall.promise.resolve(); + .and.returnValue('new-location'); + locationCapability.isOriginal.and.returnValue(true); + linkService.perform.calls.mostRecent().promise.resolve(); }); it("updates location", function () { @@ -234,8 +234,8 @@ define( describe("when moving a link", function () { beforeEach(function () { - locationCapability.isOriginal.andReturn(false); - linkService.perform.mostRecentCall.promise.resolve(); + locationCapability.isOriginal.and.returnValue(false); + linkService.perform.calls.mostRecent().promise.resolve(); }); it("does not update location", function () { diff --git a/platform/execution/test/WorkerServiceSpec.js b/platform/execution/test/WorkerServiceSpec.js index a6ab49fb8b..380d366ebf 100644 --- a/platform/execution/test/WorkerServiceSpec.js +++ b/platform/execution/test/WorkerServiceSpec.js @@ -62,8 +62,8 @@ define( mockWorker = {}; mockSharedWorker = {}; - mockWindow.Worker.andReturn(mockWorker); - mockWindow.SharedWorker.andReturn(mockSharedWorker); + mockWindow.Worker.and.returnValue(mockWorker); + mockWindow.SharedWorker.and.returnValue(mockSharedWorker); service = new WorkerService(mockWindow, testWorkers); }); diff --git a/platform/exporters/ExportServiceSpec.js b/platform/exporters/ExportServiceSpec.js index 18af713e2e..000b53a9c3 100644 --- a/platform/exporters/ExportServiceSpec.js +++ b/platform/exporters/ExportServiceSpec.js @@ -28,13 +28,11 @@ define( var mockSaveAs, testRows, csvContents, + readCSVPromise, exportService; - function finishedReadingCSV() { - return !!csvContents; - } - beforeEach(function () { + var resolveFunction; csvContents = undefined; testRows = [ { a: 1, b: 2, c: 3 }, @@ -42,10 +40,14 @@ define( { a: 7, b: 8, c: 9 } ]; mockSaveAs = jasmine.createSpy('saveAs'); - mockSaveAs.andCallFake(function (blob) { + readCSVPromise = new Promise(function (resolve) { + resolveFunction = resolve; + }); + mockSaveAs.and.callFake(function (blob) { var reader = new FileReader(); reader.onloadend = function () { csvContents = new CSV(reader.result).parse(); + resolveFunction(); }; reader.readAsText(blob); }); @@ -55,7 +57,7 @@ define( describe("#exportCSV(rows)", function () { beforeEach(function () { exportService.exportCSV(testRows); - waitsFor(finishedReadingCSV); + return readCSVPromise; }); it("triggers saving of a file", function () { @@ -89,7 +91,8 @@ define( testHeaders = ['a', 'b']; exportService .exportCSV(testRows, { headers: testHeaders }); - waitsFor(finishedReadingCSV); + + return readCSVPromise; }); it("triggers saving of a file", function () { @@ -124,7 +127,7 @@ define( testFilename = "some-test-filename.csv"; exportService .exportCSV(testRows, { filename: testFilename }); - waitsFor(finishedReadingCSV); + return readCSVPromise; }); it("saves a file with the specified name", function () { diff --git a/platform/features/clock/test/actions/FollowTimerActionSpec.js b/platform/features/clock/test/actions/FollowTimerActionSpec.js index f4b4147adb..d0671f9925 100644 --- a/platform/features/clock/test/actions/FollowTimerActionSpec.js +++ b/platform/features/clock/test/actions/FollowTimerActionSpec.js @@ -38,8 +38,8 @@ define([ 'useCapability' ]) }; testAdaptedObject = { foo: 'bar' }; - testContext.domainObject.getModel.andReturn(testModel); - testContext.domainObject.useCapability.andCallFake(function (c) { + testContext.domainObject.getModel.and.returnValue(testModel); + testContext.domainObject.useCapability.and.callFake(function (c) { return c === 'adapter' && testAdaptedObject; }); }); diff --git a/platform/features/clock/test/actions/PauseTimerActionSpec.js b/platform/features/clock/test/actions/PauseTimerActionSpec.js index 098e29c634..f68b0c461d 100644 --- a/platform/features/clock/test/actions/PauseTimerActionSpec.js +++ b/platform/features/clock/test/actions/PauseTimerActionSpec.js @@ -58,13 +58,13 @@ define( ['getCapability', 'useCapability', 'getModel'] ); - mockDomainObject.useCapability.andCallFake(function (c, v) { + mockDomainObject.useCapability.and.callFake(function (c, v) { if (c === 'mutation') { testModel = v(testModel) || testModel; return asPromise(true); } }); - mockDomainObject.getModel.andCallFake(function () { + mockDomainObject.getModel.and.callFake(function () { return testModel; }); @@ -82,7 +82,7 @@ define( it("updates the model with a pausedTime", function () { testModel.pausedTime = undefined; - mockNow.andReturn(12000); + mockNow.and.returnValue(12000); action.perform(); expect(testModel.pausedTime).toEqual(12000); }); diff --git a/platform/features/clock/test/actions/RestartTimerActionSpec.js b/platform/features/clock/test/actions/RestartTimerActionSpec.js index fc1978322f..a3e05d2d81 100644 --- a/platform/features/clock/test/actions/RestartTimerActionSpec.js +++ b/platform/features/clock/test/actions/RestartTimerActionSpec.js @@ -58,13 +58,13 @@ define( ['getCapability', 'useCapability', 'getModel'] ); - mockDomainObject.useCapability.andCallFake(function (c, v) { + mockDomainObject.useCapability.and.callFake(function (c, v) { if (c === 'mutation') { testModel = v(testModel) || testModel; return asPromise(true); } }); - mockDomainObject.getModel.andCallFake(function () { + mockDomainObject.getModel.and.callFake(function () { return testModel; }); @@ -76,7 +76,7 @@ define( it("updates the model with a timestamp", function () { testModel.pausedTime = 12000; - mockNow.andReturn(12000); + mockNow.and.returnValue(12000); action.perform(); expect(testModel.timestamp).toEqual(12000); }); diff --git a/platform/features/clock/test/actions/StartTimerActionSpec.js b/platform/features/clock/test/actions/StartTimerActionSpec.js index 1506c79738..23da7e5434 100644 --- a/platform/features/clock/test/actions/StartTimerActionSpec.js +++ b/platform/features/clock/test/actions/StartTimerActionSpec.js @@ -58,13 +58,13 @@ define( ['getCapability', 'useCapability', 'getModel'] ); - mockDomainObject.useCapability.andCallFake(function (c, v) { + mockDomainObject.useCapability.and.callFake(function (c, v) { if (c === 'mutation') { testModel = v(testModel) || testModel; return asPromise(true); } }); - mockDomainObject.getModel.andCallFake(function () { + mockDomainObject.getModel.and.callFake(function () { return testModel; }); @@ -75,7 +75,7 @@ define( }); it("updates the model with a timestamp", function () { - mockNow.andReturn(12000); + mockNow.and.returnValue(12000); action.perform(); expect(testModel.timestamp).toEqual(12000); }); diff --git a/platform/features/clock/test/actions/StopTimerActionSpec.js b/platform/features/clock/test/actions/StopTimerActionSpec.js index a4c27ad921..1dcfd58d11 100644 --- a/platform/features/clock/test/actions/StopTimerActionSpec.js +++ b/platform/features/clock/test/actions/StopTimerActionSpec.js @@ -58,13 +58,13 @@ define( ['getCapability', 'useCapability', 'getModel'] ); - mockDomainObject.useCapability.andCallFake(function (c, v) { + mockDomainObject.useCapability.and.callFake(function (c, v) { if (c === 'mutation') { testModel = v(testModel) || testModel; return asPromise(true); } }); - mockDomainObject.getModel.andCallFake(function () { + mockDomainObject.getModel.and.callFake(function () { return testModel; }); @@ -75,7 +75,7 @@ define( }); it("updates the model with a timestamp", function () { - mockNow.andReturn(12000); + mockNow.and.returnValue(12000); action.perform(); expect(testModel.timestamp).toEqual(undefined); }); diff --git a/platform/features/clock/test/controllers/ClockControllerSpec.js b/platform/features/clock/test/controllers/ClockControllerSpec.js index 8774333d14..d53987a632 100644 --- a/platform/features/clock/test/controllers/ClockControllerSpec.js +++ b/platform/features/clock/test/controllers/ClockControllerSpec.js @@ -38,7 +38,7 @@ define( mockTicker = jasmine.createSpyObj('ticker', ['listen']); mockUnticker = jasmine.createSpy('unticker'); - mockTicker.listen.andReturn(mockUnticker); + mockTicker.listen.and.returnValue(mockUnticker); controller = new ClockController(mockScope, mockTicker); }); @@ -57,17 +57,17 @@ define( it("unsubscribes to ticks when destroyed", function () { // Make sure $destroy is being listened for... - expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy'); + expect(mockScope.$on.calls.mostRecent().args[0]).toEqual('$destroy'); expect(mockUnticker).not.toHaveBeenCalled(); // ...and makes sure that its listener unsubscribes from ticker - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); expect(mockUnticker).toHaveBeenCalled(); }); it("formats using the format string from the model", function () { - mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP); - mockScope.$watch.mostRecentCall.args[1]({ + mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP); + mockScope.$watch.calls.mostRecent().args[1]({ "clockFormat": [ "YYYY-DDD hh:mm:ss", "clock24" @@ -81,8 +81,8 @@ define( }); it("formats 12-hour time", function () { - mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP); - mockScope.$watch.mostRecentCall.args[1]({ + mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP); + mockScope.$watch.calls.mostRecent().args[1]({ "clockFormat": [ "YYYY-DDD hh:mm:ss", "clock12" @@ -96,9 +96,9 @@ define( }); it("does not throw exceptions when model is undefined", function () { - mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP); + mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP); expect(function () { - mockScope.$watch.mostRecentCall.args[1](undefined); + mockScope.$watch.calls.mostRecent().args[1](undefined); }).not.toThrow(); }); diff --git a/platform/features/clock/test/controllers/RefreshingControllerSpec.js b/platform/features/clock/test/controllers/RefreshingControllerSpec.js index 75bfaf0843..4e0577aaae 100644 --- a/platform/features/clock/test/controllers/RefreshingControllerSpec.js +++ b/platform/features/clock/test/controllers/RefreshingControllerSpec.js @@ -37,7 +37,7 @@ define( mockTicker = jasmine.createSpyObj('ticker', ['listen']); mockUnticker = jasmine.createSpy('unticker'); - mockTicker.listen.andReturn(mockUnticker); + mockTicker.listen.and.returnValue(mockUnticker); controller = new RefreshingController(mockScope, mockTicker); }); @@ -52,13 +52,13 @@ define( ['persist', 'refresh'] ); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return (c === 'persistence') && mockPersistence; }); mockScope.domainObject = mockDomainObject; - mockTicker.listen.mostRecentCall.args[0](12321); + mockTicker.listen.calls.mostRecent().args[0](12321); expect(mockPersistence.refresh).toHaveBeenCalled(); expect(mockPersistence.persist).not.toHaveBeenCalled(); }); @@ -70,11 +70,11 @@ define( it("unsubscribes to ticks when destroyed", function () { // Make sure $destroy is being listened for... - expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy'); + expect(mockScope.$on.calls.mostRecent().args[0]).toEqual('$destroy'); expect(mockUnticker).not.toHaveBeenCalled(); // ...and makes sure that its listener unsubscribes from ticker - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); expect(mockUnticker).toHaveBeenCalled(); }); }); diff --git a/platform/features/clock/test/controllers/TimerControllerSpec.js b/platform/features/clock/test/controllers/TimerControllerSpec.js index ee8c7ca8d7..3f97c4bc80 100644 --- a/platform/features/clock/test/controllers/TimerControllerSpec.js +++ b/platform/features/clock/test/controllers/TimerControllerSpec.js @@ -40,7 +40,7 @@ define( controller; function invokeWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -78,13 +78,13 @@ define( ); mockNow = jasmine.createSpy('now'); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return (c === 'action') && mockActionCapability; }); - mockDomainObject.getModel.andCallFake(function () { + mockDomainObject.getModel.and.callFake(function () { return testModel; }); - mockActionCapability.getActions.andCallFake(function (k) { + mockActionCapability.getActions.and.callFake(function (k) { return [{ 'timer.start': mockStart, 'timer.pause': mockPause, @@ -92,9 +92,9 @@ define( }[k]]; }); - mockStart.getMetadata.andReturn({cssClass: "icon-play", name: "Start"}); - mockPause.getMetadata.andReturn({cssClass: "icon-pause", name: "Pause"}); - mockStop.getMetadata.andReturn({cssClass: "icon-box", name: "Stop"}); + mockStart.getMetadata.and.returnValue({cssClass: "icon-play", name: "Start"}); + mockPause.getMetadata.and.returnValue({cssClass: "icon-pause", name: "Pause"}); + mockStop.getMetadata.and.returnValue({cssClass: "icon-box", name: "Stop"}); mockScope.domainObject = mockDomainObject; testModel = {}; @@ -124,8 +124,8 @@ define( it("displays nothing when there is no target", function () { // Notify that domain object is available via scope invokeWatch('domainObject', mockDomainObject); - mockNow.andReturn(TEST_TIMESTAMP); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP); + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); expect(controller.sign()).toEqual(""); expect(controller.signClass()).toEqual(""); expect(controller.text()).toEqual(""); @@ -137,20 +137,20 @@ define( // Notify that domain object is available via scope invokeWatch('domainObject', mockDomainObject); - mockNow.andReturn(TEST_TIMESTAMP + 121000); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP + 121000); + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); expect(controller.sign()).toEqual("+"); expect(controller.signClass()).toEqual("icon-plus"); expect(controller.text()).toEqual("0D 00:02:01"); - mockNow.andReturn(TEST_TIMESTAMP - 121000); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP - 121000); + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); expect(controller.sign()).toEqual("-"); expect(controller.signClass()).toEqual("icon-minus"); expect(controller.text()).toEqual("0D 00:02:01"); - mockNow.andReturn(TEST_TIMESTAMP); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP); + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); expect(controller.sign()).toEqual(""); expect(controller.signClass()).toEqual(""); expect(controller.text()).toEqual("0D 00:00:00"); @@ -190,27 +190,27 @@ define( }); it("stops requesting animation frames when destroyed", function () { - var initialCount = mockWindow.requestAnimationFrame.calls.length; + var initialCount = mockWindow.requestAnimationFrame.calls.count(); // First, check that normally new frames keep getting requested - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); - expect(mockWindow.requestAnimationFrame.calls.length) + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); + expect(mockWindow.requestAnimationFrame.calls.count()) .toEqual(initialCount + 1); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); - expect(mockWindow.requestAnimationFrame.calls.length) + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); + expect(mockWindow.requestAnimationFrame.calls.count()) .toEqual(initialCount + 2); // Now, verify that it stops after $destroy - expect(mockScope.$on.mostRecentCall.args[0]) + expect(mockScope.$on.calls.mostRecent().args[0]) .toEqual('$destroy'); - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); // Frames should no longer get requested - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); - expect(mockWindow.requestAnimationFrame.calls.length) + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); + expect(mockWindow.requestAnimationFrame.calls.count()) .toEqual(initialCount + 2); - mockWindow.requestAnimationFrame.mostRecentCall.args[0](); - expect(mockWindow.requestAnimationFrame.calls.length) + mockWindow.requestAnimationFrame.calls.mostRecent().args[0](); + expect(mockWindow.requestAnimationFrame.calls.count()) .toEqual(initialCount + 2); }); }); diff --git a/platform/features/clock/test/indicators/ClockIndicatorSpec.js b/platform/features/clock/test/indicators/ClockIndicatorSpec.js index 6c9a8c2977..68d7397795 100644 --- a/platform/features/clock/test/indicators/ClockIndicatorSpec.js +++ b/platform/features/clock/test/indicators/ClockIndicatorSpec.js @@ -37,13 +37,13 @@ define( mockTicker = jasmine.createSpyObj('ticker', ['listen']); mockUnticker = jasmine.createSpy('unticker'); - mockTicker.listen.andReturn(mockUnticker); + mockTicker.listen.and.returnValue(mockUnticker); indicator = new ClockIndicator(mockTicker, TEST_FORMAT); }); it("displays the current time", function () { - mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP); + mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP); expect(indicator.getText()).toEqual("2015-154 17:56:14 UTC"); }); diff --git a/platform/features/clock/test/indicators/FollowIndicatorSpec.js b/platform/features/clock/test/indicators/FollowIndicatorSpec.js index 0e4f4c6a01..0bcc13397c 100644 --- a/platform/features/clock/test/indicators/FollowIndicatorSpec.js +++ b/platform/features/clock/test/indicators/FollowIndicatorSpec.js @@ -46,7 +46,7 @@ define(["../../src/indicators/FollowIndicator"], function (FollowIndicator) { beforeEach(function () { testObject = { name: "some timer!" }; - mockTimerService.getTimer.andReturn(testObject); + mockTimerService.getTimer.and.returnValue(testObject); }); it("displays the timer's name", function () { diff --git a/platform/features/clock/test/services/TickerServiceSpec.js b/platform/features/clock/test/services/TickerServiceSpec.js index 9331f49dbe..a7fb257fb7 100644 --- a/platform/features/clock/test/services/TickerServiceSpec.js +++ b/platform/features/clock/test/services/TickerServiceSpec.js @@ -37,23 +37,23 @@ define( mockNow = jasmine.createSpy('now'); mockCallback = jasmine.createSpy('callback'); - mockNow.andReturn(TEST_TIMESTAMP); + mockNow.and.returnValue(TEST_TIMESTAMP); tickerService = new TickerService(mockTimeout, mockNow); }); it("notifies listeners of clock ticks", function () { tickerService.listen(mockCallback); - mockNow.andReturn(TEST_TIMESTAMP + 12321); - mockTimeout.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP + 12321); + mockTimeout.calls.mostRecent().args[0](); expect(mockCallback) .toHaveBeenCalledWith(TEST_TIMESTAMP + 12321); }); it("allows listeners to unregister", function () { tickerService.listen(mockCallback)(); // Unregister immediately - mockNow.andReturn(TEST_TIMESTAMP + 12321); - mockTimeout.mostRecentCall.args[0](); + mockNow.and.returnValue(TEST_TIMESTAMP + 12321); + mockTimeout.calls.mostRecent().args[0](); expect(mockCallback).not .toHaveBeenCalledWith(TEST_TIMESTAMP + 12321); }); diff --git a/platform/features/clock/test/services/TimerServiceSpec.js b/platform/features/clock/test/services/TimerServiceSpec.js index 08f05c83fd..3c57ba2e2e 100644 --- a/platform/features/clock/test/services/TimerServiceSpec.js +++ b/platform/features/clock/test/services/TimerServiceSpec.js @@ -69,7 +69,7 @@ define([ '*', jasmine.any(Function) ); - mockmct.objects.observe.mostRecentCall.args[2](newTimer); + mockmct.objects.observe.calls.mostRecent().args[2](newTimer); expect(timerService.getTimer()).toBe(newTimer); }); }); diff --git a/platform/features/conductor/core/src/ui/ConductorAxisControllerSpec.js b/platform/features/conductor/core/src/ui/ConductorAxisControllerSpec.js index 3f87490341..f1a3d0df70 100644 --- a/platform/features/conductor/core/src/ui/ConductorAxisControllerSpec.js +++ b/platform/features/conductor/core/src/ui/ConductorAxisControllerSpec.js @@ -45,7 +45,7 @@ define([ mockFormat; function getCallback(target, name) { - return target.calls.filter(function (call) { + return target.calls.all().filter(function (call) { return call.args[0] === name; })[0].args[1]; } @@ -74,7 +74,7 @@ define([ "off", "clock" ]); - mockConductor.bounds.andReturn(mockBounds); + mockConductor.bounds.and.returnValue(mockBounds); mockFormatService = jasmine.createSpyObj("formatService", [ "getFormat" @@ -86,8 +86,8 @@ define([ "emit" ]); - spyOn(d3Scale, 'scaleUtc').andCallThrough(); - spyOn(d3Scale, 'scaleLinear').andCallThrough(); + spyOn(d3Scale, 'scaleUtc').and.callThrough(); + spyOn(d3Scale, 'scaleLinear').and.callThrough(); element = $('
'); $(document).find('body').append(element); @@ -100,8 +100,8 @@ define([ ]); mockTimeSystem.timeFormat = "mockFormat"; - mockFormatService.getFormat.andReturn(mockFormat); - mockConductor.timeSystem.andReturn(mockTimeSystem); + mockFormatService.getFormat.and.returnValue(mockFormat); + mockConductor.timeSystem.and.returnValue(mockTimeSystem); mockTimeSystem.isUTCBased = false; }); @@ -148,19 +148,19 @@ define([ it('responds to zoom events', function () { expect(mockConductorViewService.on).toHaveBeenCalledWith("zoom", controller.onZoom); var cb = getCallback(mockConductorViewService.on, "zoom"); - spyOn(controller, 'setScale').andCallThrough(); + spyOn(controller, 'setScale').and.callThrough(); cb({bounds: {start: 0, end: 100}}); expect(controller.setScale).toHaveBeenCalled(); }); it('adjusts scale on pan', function () { - spyOn(controller, 'setScale').andCallThrough(); + spyOn(controller, 'setScale').and.callThrough(); controller.pan(100); expect(controller.setScale).toHaveBeenCalled(); }); it('emits event on pan', function () { - spyOn(controller, 'setScale').andCallThrough(); + spyOn(controller, 'setScale').and.callThrough(); controller.pan(100); expect(mockConductorViewService.emit).toHaveBeenCalledWith("pan", jasmine.any(Object)); }); diff --git a/platform/features/conductor/core/src/ui/ConductorTOIControllerSpec.js b/platform/features/conductor/core/src/ui/ConductorTOIControllerSpec.js index fca6a2bcbe..7b2aa5004a 100644 --- a/platform/features/conductor/core/src/ui/ConductorTOIControllerSpec.js +++ b/platform/features/conductor/core/src/ui/ConductorTOIControllerSpec.js @@ -32,7 +32,7 @@ define([ var conductorTOIController; function getNamedCallback(thing, name) { - return thing.calls.filter(function (call) { + return thing.calls.all().filter(function (call) { return call.args[0] === name; }).map(function (call) { return call.args; @@ -72,35 +72,35 @@ define([ start: 0, end: 200 }; - mockConductor.bounds.andReturn(bounds); + mockConductor.bounds.and.returnValue(bounds); toiCallback = getNamedCallback(mockConductor.on, "timeOfInterest"); }); it("calculates the correct horizontal offset based on bounds and current TOI", function () { //Expect time of interest position to be 50% of element width - mockConductor.timeOfInterest.andReturn(100); + mockConductor.timeOfInterest.and.returnValue(100); toiCallback(); expect(conductorTOIController.left).toBe(50); //Expect time of interest position to be 25% of element width - mockConductor.timeOfInterest.andReturn(50); + mockConductor.timeOfInterest.and.returnValue(50); toiCallback(); expect(conductorTOIController.left).toBe(25); //Expect time of interest position to be 0% of element width - mockConductor.timeOfInterest.andReturn(0); + mockConductor.timeOfInterest.and.returnValue(0); toiCallback(); expect(conductorTOIController.left).toBe(0); //Expect time of interest position to be 100% of element width - mockConductor.timeOfInterest.andReturn(200); + mockConductor.timeOfInterest.and.returnValue(200); toiCallback(); expect(conductorTOIController.left).toBe(100); }); it("renders the TOI indicator visible", function () { expect(conductorTOIController.pinned).toBeFalsy(); - mockConductor.timeOfInterest.andReturn(100); + mockConductor.timeOfInterest.and.returnValue(100); toiCallback(); expect(conductorTOIController.pinned).toBe(true); }); @@ -116,7 +116,7 @@ define([ expect(mockConductorViewService.on).toHaveBeenCalledWith("zoom", jasmine.any(Function)); // Should correspond to horizontal offset of 50% - mockConductor.timeOfInterest.andReturn(750); + mockConductor.timeOfInterest.and.returnValue(750); var zoomCallback = getNamedCallback(mockConductorViewService.on, "zoom"); zoomCallback(mockZoom); expect(conductorTOIController.left).toBe(50); @@ -131,7 +131,7 @@ define([ expect(mockConductorViewService.on).toHaveBeenCalledWith("pan", jasmine.any(Function)); // Should correspond to horizontal offset of 25% - mockConductor.timeOfInterest.andReturn(1500); + mockConductor.timeOfInterest.and.returnValue(1500); var panCallback = getNamedCallback(mockConductorViewService.on, "pan"); panCallback(mockPanBounds); expect(conductorTOIController.left).toBe(25); diff --git a/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js b/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js index 983d641001..c49bd110a7 100644 --- a/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js +++ b/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js @@ -48,7 +48,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { "off" ] ); - mockTimeConductor.bounds.andReturn({start: undefined, end: undefined}); + mockTimeConductor.bounds.and.returnValue({start: undefined, end: undefined}); mockConductorViewService = jasmine.createSpyObj( "ConductorViewService", @@ -62,8 +62,8 @@ define(['./TimeConductorController'], function (TimeConductorController) { "off" ] ); - mockConductorViewService.availableModes.andReturn([]); - mockConductorViewService.availableTimeSystems.andReturn([]); + mockConductorViewService.availableModes.and.returnValue([]); + mockConductorViewService.availableTimeSystems.and.returnValue([]); mockFormatService = jasmine.createSpyObj('formatService', [ 'getFormat' @@ -71,17 +71,17 @@ define(['./TimeConductorController'], function (TimeConductorController) { mockFormat = jasmine.createSpyObj('format', [ 'format' ]); - mockFormatService.getFormat.andReturn(mockFormat); + mockFormatService.getFormat.and.returnValue(mockFormat); mockLocation = jasmine.createSpyObj('location', [ 'search' ]); - mockLocation.search.andReturn({}); + mockLocation.search.and.returnValue({}); mockTimeSystems = []; }); function getListener(target, event) { - return target.calls.filter(function (call) { + return target.calls.all().filter(function (call) { return call.args[0] === event; })[0].args[1]; } @@ -167,7 +167,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { min: 100, max: 10 }; - mockTimeConductor.timeSystem.andReturn(timeSystem); + mockTimeConductor.timeSystem.and.returnValue(timeSystem); tsListener(timeSystem); expect(mockScope.boundsModel.start).toEqual(defaultBounds.start); @@ -216,7 +216,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { return 1 - Math.pow(rawValue, 1 / 4); } - mockTimeConductor.timeSystem.andReturn(timeSystem); + mockTimeConductor.timeSystem.and.returnValue(timeSystem); //Set zoom defaults tsListener(timeSystem); @@ -292,14 +292,14 @@ define(['./TimeConductorController'], function (TimeConductorController) { }); it("sets the mode on scope", function () { - mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems); + mockConductorViewService.availableTimeSystems.and.returnValue(mockTimeSystems); controller.setMode(mode); expect(mockScope.modeModel.selectedKey).toEqual(mode); }); it("sets available time systems on scope when mode changes", function () { - mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems); + mockConductorViewService.availableTimeSystems.and.returnValue(mockTimeSystems); controller.setMode(mode); expect(mockScope.timeSystemModel.options.length).toEqual(3); @@ -451,8 +451,8 @@ define(['./TimeConductorController'], function (TimeConductorController) { "tc.endDelta": urlDeltas.end, "tc.timeSystem": urlTimeSystem }; - mockLocation.search.andReturn(mockSearchObject); - mockTimeConductor.timeSystem.andReturn(timeSystem); + mockLocation.search.and.returnValue(mockSearchObject); + mockTimeConductor.timeSystem.and.returnValue(timeSystem); controller = new TimeConductorController( mockScope, @@ -493,7 +493,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { }); it("updates the URL with the bounds", function () { - mockConductorViewService.mode.andReturn("fixed"); + mockConductorViewService.mode.and.returnValue("fixed"); controller.changeBounds({start: 500, end: 600}); expect(mockLocation.search).toHaveBeenCalledWith("tc.startBound", 500); expect(mockLocation.search).toHaveBeenCalledWith("tc.endBound", 600); diff --git a/platform/features/conductor/core/src/ui/TimeConductorValidationSpec.js b/platform/features/conductor/core/src/ui/TimeConductorValidationSpec.js index a8297d4199..c5951db2a7 100644 --- a/platform/features/conductor/core/src/ui/TimeConductorValidationSpec.js +++ b/platform/features/conductor/core/src/ui/TimeConductorValidationSpec.js @@ -40,7 +40,7 @@ define(['./TimeConductorValidation'], function (TimeConductorValidation) { end: 20 }; - mockTimeConductor.bounds.andReturn(mockBounds); + mockTimeConductor.bounds.and.returnValue(mockBounds); }); it("Validates start values using Time Conductor", function () { diff --git a/platform/features/hyperlink/test/HyperlinkControllerSpec.js b/platform/features/hyperlink/test/HyperlinkControllerSpec.js index de941b54be..bd89b2615f 100644 --- a/platform/features/hyperlink/test/HyperlinkControllerSpec.js +++ b/platform/features/hyperlink/test/HyperlinkControllerSpec.js @@ -41,7 +41,7 @@ define( controller = new HyperlinkController(scope); }); it("knows when it should open a new tab", function () { - scope.domainObject.getModel.andReturn({ + scope.domainObject.getModel.and.returnValue({ "displayFormat": "link", "openNewTab": "newTab", "showTitle": false @@ -52,7 +52,7 @@ define( .toBe(true); }); it("knows when it is a button", function () { - scope.domainObject.getModel.andReturn({ + scope.domainObject.getModel.and.returnValue({ "displayFormat": "button", "openNewTab": "thisTab", "showTitle": false @@ -63,7 +63,7 @@ define( .toEqual(true); }); it("knows when it should open in the same tab", function () { - scope.domainObject.getModel.andReturn({ + scope.domainObject.getModel.and.returnValue({ "displayFormat": "link", "openNewTab": "thisTab", "showTitle": false @@ -74,7 +74,7 @@ define( .toBe(false); }); it("knows when it is a link", function () { - scope.domainObject.getModel.andReturn({ + scope.domainObject.getModel.and.returnValue({ "displayFormat": "link", "openNewTab": "thisTab", "showTitle": false diff --git a/platform/features/imagery/test/controllers/ImageryControllerSpec.js b/platform/features/imagery/test/controllers/ImageryControllerSpec.js index c63e37e882..a804a873ff 100644 --- a/platform/features/imagery/test/controllers/ImageryControllerSpec.js +++ b/platform/features/imagery/test/controllers/ImageryControllerSpec.js @@ -39,7 +39,7 @@ define( metadata, prefix, controller, - hasLoaded, + requestPromise, mockWindow, mockElement; @@ -50,7 +50,7 @@ define( ['getId'] ); newDomainObject = { name: 'foo' }; - oldDomainObject.getId.andReturn('testID'); + oldDomainObject.getId.and.returnValue('testID'); openmct = { objects: jasmine.createSpyObj('objectAPI', [ 'get' @@ -73,39 +73,41 @@ define( 'value', 'valuesForHints' ]); + metadata.value.and.returnValue("timestamp"); + metadata.valuesForHints.and.returnValue(["value"]); + prefix = "formatted "; unsubscribe = jasmine.createSpy('unsubscribe'); - openmct.telemetry.subscribe.andReturn(unsubscribe); - openmct.time.timeSystem.andReturn({ + openmct.telemetry.subscribe.and.returnValue(unsubscribe); + openmct.time.timeSystem.and.returnValue({ key: 'testKey' }); $scope.domainObject = oldDomainObject; - openmct.objects.get.andReturn(Promise.resolve(newDomainObject)); - openmct.telemetry.getMetadata.andReturn(metadata); - openmct.telemetry.getValueFormatter.andCallFake(function (property) { + openmct.objects.get.and.returnValue(Promise.resolve(newDomainObject)); + openmct.telemetry.getMetadata.and.returnValue(metadata); + openmct.telemetry.getValueFormatter.and.callFake(function (property) { var formatter = jasmine.createSpyObj("formatter-" + property, ['format']); var isTime = (property === "timestamp"); - formatter.format.andCallFake(function (datum) { + formatter.format.and.callFake(function (datum) { return (isTime ? prefix : "") + datum[property]; }); return formatter; }); - hasLoaded = false; - openmct.telemetry.request.andCallFake(function () { + + requestPromise = new Promise(function (resolve) { setTimeout(function () { - hasLoaded = true; - }, 10); - return Promise.resolve([{ + resolve([{ timestamp: 1434600258123, value: 'some/url' }]); + }, 10); }); - metadata.value.andReturn("timestamp"); - metadata.valuesForHints.andReturn(["value"]); + + openmct.telemetry.request.and.returnValue(requestPromise); mockElement = $(MOCK_ELEMENT_TEMPLATE); mockWindow = jasmine.createSpyObj('$window', ['requestAnimationFrame']); - mockWindow.requestAnimationFrame.andCallFake(function (f) { + mockWindow.requestAnimationFrame.and.callFake(function (f) { return f(); }); @@ -123,19 +125,14 @@ define( bounds; beforeEach(function () { - waitsFor(function () { - return hasLoaded; - }, 500); - - - runs(function () { - openmct.time.on.calls.forEach(function (call) { + return requestPromise.then(function () { + openmct.time.on.calls.all().forEach(function (call) { if (call.args[0] === "bounds") { boundsListener = call.args[1]; } }); callback = - openmct.telemetry.subscribe.mostRecentCall.args[1]; + openmct.telemetry.subscribe.calls.mostRecent().args[1]; }); }); @@ -209,7 +206,7 @@ define( it("unsubscribes and unlistens when scope is destroyed", function () { expect(unsubscribe).not.toHaveBeenCalled(); - $scope.$on.calls.forEach(function (call) { + $scope.$on.calls.all().forEach(function (call) { if (call.args[0] === '$destroy') { call.args[1](); } @@ -222,7 +219,7 @@ define( it("listens for bounds event and responds to tick and manual change", function () { var mockBounds = {start: 1434600000000, end: 1434600500000}; expect(openmct.time.on).toHaveBeenCalled(); - openmct.telemetry.request.reset(); + openmct.telemetry.request.calls.reset(); boundsListener(mockBounds, true); expect(openmct.telemetry.request).not.toHaveBeenCalled(); boundsListener(mockBounds, false); diff --git a/platform/features/imagery/test/directives/MCTBackgroundImageSpec.js b/platform/features/imagery/test/directives/MCTBackgroundImageSpec.js index d171a59d9c..dd6182be54 100644 --- a/platform/features/imagery/test/directives/MCTBackgroundImageSpec.js +++ b/platform/features/imagery/test/directives/MCTBackgroundImageSpec.js @@ -42,7 +42,7 @@ define( mockElement = jasmine.createSpyObj('element', ['css']); testImage = {}; - mockDocument[0].createElement.andReturn(testImage); + mockDocument[0].createElement.and.returnValue(testImage); directive = new MCTBackgroundImage(mockDocument); }); @@ -70,28 +70,28 @@ define( it("updates images in-order, even when they load out-of-order", function () { var firstOnload; - mockScope.$watch.mostRecentCall.args[1]("some/url/0"); + mockScope.$watch.calls.mostRecent().args[1]("some/url/0"); firstOnload = testImage.onload; - mockScope.$watch.mostRecentCall.args[1]("some/url/1"); + mockScope.$watch.calls.mostRecent().args[1]("some/url/1"); // Resolve in a different order testImage.onload(); firstOnload(); // Should still have taken the more recent value - expect(mockElement.css.mostRecentCall.args).toEqual([ + expect(mockElement.css.calls.mostRecent().args).toEqual([ "background-image", "url('some/url/1')" ]); }); it("clears the background image when undefined is passed in", function () { - mockScope.$watch.mostRecentCall.args[1]("some/url/0"); + mockScope.$watch.calls.mostRecent().args[1]("some/url/0"); testImage.onload(); - mockScope.$watch.mostRecentCall.args[1](undefined); + mockScope.$watch.calls.mostRecent().args[1](undefined); - expect(mockElement.css.mostRecentCall.args).toEqual([ + expect(mockElement.css.calls.mostRecent().args).toEqual([ "background-image", "none" ]); @@ -99,7 +99,7 @@ define( it("updates filters on change", function () { var filters = { brightness: 123, contrast: 21 }; - mockScope.$watchCollection.calls.forEach(function (call) { + mockScope.$watchCollection.calls.all().forEach(function (call) { if (call.args[0] === 'filters') { call.args[1](filters); } @@ -111,7 +111,7 @@ define( }); it("clears filters when none are present", function () { - mockScope.$watchCollection.calls.forEach(function (call) { + mockScope.$watchCollection.calls.all().forEach(function (call) { if (call.args[0] === 'filters') { call.args[1](undefined); } diff --git a/platform/features/imagery/test/policies/ImageryViewPolicySpec.js b/platform/features/imagery/test/policies/ImageryViewPolicySpec.js index 3218ce9ce5..de61a91100 100644 --- a/platform/features/imagery/test/policies/ImageryViewPolicySpec.js +++ b/platform/features/imagery/test/policies/ImageryViewPolicySpec.js @@ -45,13 +45,13 @@ define( 'telemetry', ['getMetadata'] ); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return c === 'telemetry' ? mockTelemetry : undefined; }); - mockDomainObject.getId.andReturn("some-id"); - mockDomainObject.getModel.andReturn({ name: "foo" }); - mockTelemetry.getMetadata.andReturn(mockMetadata); - mockMetadata.valuesForHints.andReturn(["bar"]); + mockDomainObject.getId.and.returnValue("some-id"); + mockDomainObject.getModel.and.returnValue({ name: "foo" }); + mockTelemetry.getMetadata.and.returnValue(mockMetadata); + mockMetadata.valuesForHints.and.returnValue(["bar"]); openmct = { telemetry: mockTelemetry }; @@ -69,7 +69,7 @@ define( }); it("disallows the imagery view for domain objects without image telemetry", function () { - mockMetadata.valuesForHints.andReturn([]); + mockMetadata.valuesForHints.and.returnValue([]); expect(policy.allow(testView, mockDomainObject)).toBeFalsy(); }); diff --git a/platform/features/layout/test/FixedControllerSpec.js b/platform/features/layout/test/FixedControllerSpec.js index 5c262195ad..9506dd9d78 100644 --- a/platform/features/layout/test/FixedControllerSpec.js +++ b/platform/features/layout/test/FixedControllerSpec.js @@ -34,14 +34,11 @@ define( var mockScope, mockQ, mockDialogService, - mockHandler, mockFormatter, mockDomainObject, - mockHandle, mockEvent, testGrid, testModel, - testValues, testConfiguration, mockOpenMCT, mockTelemetryAPI, @@ -63,7 +60,7 @@ define( // Utility function; find a $on calls for a given expression. function findOn(expr) { var on; - mockScope.$on.calls.forEach(function (call) { + mockScope.$on.calls.all().forEach(function (call) { if (call.args[0] === expr) { on = call.args[1]; } @@ -86,10 +83,6 @@ define( '$scope', ["$on", "$watch", "$digest", "commit"] ); - mockHandler = jasmine.createSpyObj( - 'telemetryHandler', - ['handle'] - ); mockQ = jasmine.createSpyObj('$q', ['when']); mockDialogService = jasmine.createSpyObj( 'dialogService', @@ -99,21 +92,10 @@ define( 'telemetryFormatter', ['format'] ); - mockFormatter.format.andCallFake(function (valueMetadata) { + mockFormatter.format.and.callFake(function (valueMetadata) { return "Formatted " + valueMetadata.value; }); - mockHandle = jasmine.createSpyObj( - 'subscription', - [ - 'unsubscribe', - 'getDomainValue', - 'getTelemetryObjects', - 'getRangeValue', - 'getDatum', - 'request' - ] - ); mockConductor = jasmine.createSpyObj('conductor', [ 'on', 'off', @@ -121,13 +103,13 @@ define( 'timeSystem', 'clock' ]); - mockConductor.bounds.andReturn({}); + mockConductor.bounds.and.returnValue({}); mockTimeSystem = { metadata: { key: 'key' } }; - mockConductor.timeSystem.andReturn(mockTimeSystem); + mockConductor.timeSystem.and.returnValue(mockTimeSystem); mockEvent = jasmine.createSpyObj( 'event', @@ -144,15 +126,14 @@ define( 'getValueFormatter' ] ); - mockTelemetryAPI.isTelemetryObject.andReturn(true); - mockTelemetryAPI.request.andReturn(Promise.resolve([])); + mockTelemetryAPI.isTelemetryObject.and.returnValue(true); + mockTelemetryAPI.request.and.returnValue(Promise.resolve([])); testGrid = [123, 456]; testModel = { composition: ['a', 'b', 'c'], layoutGrid: testGrid }; - testValues = { a: 10, b: 42, c: 31.42 }; testConfiguration = { elements: [ { type: "fixed.telemetry", id: 'a', x: 1, y: 1, useGrid: true}, { type: "fixed.telemetry", id: 'b', x: 1, y: 1, useGrid: true}, @@ -168,8 +149,8 @@ define( mockCompositionAPI = jasmine.createSpyObj('composition', [ 'get' ]); - mockCompositionAPI.get.andReturn(mockCompositionCollection); - mockCompositionCollection.load.andReturn( + mockCompositionAPI.get.and.returnValue(mockCompositionCollection); + mockCompositionCollection.load.and.returnValue( Promise.resolve(mockChildren) ); @@ -191,7 +172,7 @@ define( 'domainObject', ['getId', 'getModel', 'getCapability', 'useCapability'] ); - mockDomainObject.useCapability.andReturn(mockNewDomainObject); + mockDomainObject.useCapability.and.returnValue(mockNewDomainObject); mockScope.domainObject = mockDomainObject; selectable[0] = { @@ -205,14 +186,14 @@ define( 'off', 'get' ]); - mockSelection.get.andReturn([]); + mockSelection.get.and.returnValue([]); unlistenFunc = jasmine.createSpy("unlisten"); mockObjects = jasmine.createSpyObj('objects', [ 'observe', 'get' ]); - mockObjects.observe.andReturn(unlistenFunc); + mockObjects.observe.and.returnValue(unlistenFunc); mockOpenMCT = { time: mockConductor, @@ -230,11 +211,11 @@ define( 'value', 'values' ]); - mockMetadata.value.andReturn({ + mockMetadata.value.and.returnValue({ key: 'value' }); - mockMetadata.valuesForHints.andCallFake(function (hints) { + mockMetadata.valuesForHints.and.callFake(function (hints) { if (hints === ['domain']) { return [{ key: 'time' @@ -250,11 +231,11 @@ define( 'evaluate' ]); - mockLimitEvaluator.evaluate.andReturn({}); + mockLimitEvaluator.evaluate.and.returnValue({}); - mockTelemetryAPI.getMetadata.andReturn(mockMetadata); - mockTelemetryAPI.limitEvaluator.andReturn(mockLimitEvaluator); - mockTelemetryAPI.getValueFormatter.andReturn(mockFormatter); + mockTelemetryAPI.getMetadata.and.returnValue(mockMetadata); + mockTelemetryAPI.limitEvaluator.and.returnValue(mockLimitEvaluator); + mockTelemetryAPI.getValueFormatter.and.returnValue(mockFormatter); controller = new FixedController( mockScope, @@ -268,17 +249,8 @@ define( it("subscribes a domain object", function () { var object = makeMockDomainObject("mock"); - var done = false; - controller.getTelemetry(object).then(function () { - done = true; - }); - - waitsFor(function () { - return done; - }); - - runs(function () { + return controller.getTelemetry(object).then(function () { expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith( object, jasmine.any(Function), @@ -288,29 +260,18 @@ define( }); it("releases subscription when a domain objects is removed", function () { - var done = false; var unsubscribe = jasmine.createSpy('unsubscribe'); + var unsubscribePromise = new Promise(function (resolve) { + unsubscribe.and.callFake(resolve); + }); var object = makeMockDomainObject("mock"); - mockTelemetryAPI.subscribe.andReturn(unsubscribe); - controller.getTelemetry(object).then(function () { - done = true; - }); - - waitsFor(function () { - return done; - }); - - runs(function () { + mockTelemetryAPI.subscribe.and.returnValue(unsubscribe); + return controller.getTelemetry(object).then(function () { controller.onCompositionRemove(object.identifier); - - waitsFor(function () { - return unsubscribe.calls.length > 0; - }); - - runs(function () { - expect(unsubscribe).toHaveBeenCalled(); - }); + return unsubscribePromise; + }).then(function () { + expect(unsubscribe).toHaveBeenCalled(); }); }); @@ -325,7 +286,7 @@ define( it("allows elements to be selected", function () { selectable[0].context.elementProxy = controller.getElements()[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(controller.isElementSelected()).toBe(true); }); @@ -333,7 +294,7 @@ define( it("allows selection retrieval", function () { var elements = controller.getElements(); selectable[0].context.elementProxy = elements[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(controller.getSelectedElement()).toEqual(elements[1]); }); @@ -341,7 +302,7 @@ define( it("selects the parent view when selected element is removed", function () { var elements = controller.getElements(); selectable[0].context.elementProxy = elements[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); controller.remove(elements[1]); expect($element[0].click).toHaveBeenCalled(); @@ -352,7 +313,7 @@ define( // Same element (at least by index) should still be selected. var elements = controller.getElements(); selectable[0].context.elementProxy = elements[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(controller.getSelectedElement()).toEqual(elements[1]); @@ -377,26 +338,23 @@ define( key: '12345' } }; - mockConductor.clock.andReturn({}); + mockConductor.clock.and.returnValue({}); controller.elementProxiesById = {}; controller.elementProxiesById['12345'] = [testElement]; controller.elementProxies = [testElement]; controller.subscribeToObject(telemetryObject); - mockTelemetryAPI.subscribe.mostRecentCall.args[1](mockTelemetry); + mockTelemetryAPI.subscribe.calls.mostRecent().args[1](mockTelemetry); - waitsFor(function () { - return controller.digesting === false; - }, "digest to complete", 100); - - runs(function () { + return new Promise(function (resolve) { + mockScope.$digest.and.callFake(resolve); + }).then(function () { // Get elements that controller is now exposing elements = controller.getElements(); // Formatted values should be available expect(elements[0].value).toEqual("Formatted 200"); }); - }); it("updates elements styles when grid size changes", function () { @@ -427,7 +385,7 @@ define( // Notify that a drop occurred testModel.composition.push('d'); - mockObjects.get.andReturn(Promise.resolve([])); + mockObjects.get.and.returnValue(Promise.resolve([])); findOn('mctDrop')( mockEvent, @@ -459,21 +417,12 @@ define( }); it("unsubscribes when destroyed", function () { - var done = false; var unsubscribe = jasmine.createSpy('unsubscribe'); var object = makeMockDomainObject("mock"); - mockTelemetryAPI.subscribe.andReturn(unsubscribe); + mockTelemetryAPI.subscribe.and.returnValue(unsubscribe); - controller.getTelemetry(object).then(function () { - done = true; - }); - - waitsFor(function () { - return done; - }); - - runs(function () { + return controller.getTelemetry(object).then(function () { expect(unsubscribe).not.toHaveBeenCalled(); // Destroy the scope findOn('$destroy')(); @@ -489,7 +438,7 @@ define( it("exposes drag handles", function () { var handles; selectable[0].context.elementProxy = controller.getElements()[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); // Should have a non-empty array of handles handles = controller.handles(); @@ -507,7 +456,7 @@ define( it("exposes a move handle", function () { selectable[0].context.elementProxy = controller.getElements()[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); // Should have a move handle var handle = controller.moveHandle(); @@ -521,7 +470,7 @@ define( it("updates selection style during drag", function () { var oldStyle; selectable[0].context.elementProxy = controller.getElements()[1]; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); // Get style oldStyle = controller.getSelectedElementStyle(); @@ -545,7 +494,7 @@ define( jasmine.any(Function) ); - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); expect(mockOpenMCT.selection.off).toHaveBeenCalledWith( 'change', @@ -561,7 +510,7 @@ define( beforeEach(function () { testBounds = { start: 123, end: 321 }; - boundsChangeCallback = mockConductor.on.mostRecentCall.args[1]; + boundsChangeCallback = mockConductor.on.calls.mostRecent().args[1]; objectOne = {}; objectTwo = {}; controller.telemetryObjects = [ @@ -569,7 +518,7 @@ define( objectTwo ]; spyOn(controller, "fetchHistoricalData"); - controller.fetchHistoricalData.andCallThrough(); + controller.fetchHistoricalData.and.callThrough(); }); it("registers a bounds change listener", function () { @@ -577,18 +526,18 @@ define( }); it("requests only a single point", function () { - mockConductor.clock.andReturn(undefined); + mockConductor.clock.and.returnValue(undefined); boundsChangeCallback(testBounds); - expect(mockTelemetryAPI.request.calls.length).toBe(2); + expect(mockTelemetryAPI.request.calls.count()).toBe(2); - mockTelemetryAPI.request.calls.forEach(function (call) { + mockTelemetryAPI.request.calls.all().forEach(function (call) { expect(call.args[1].size).toBe(1); }); }); it("Does not fetch historical data on tick", function () { boundsChangeCallback(testBounds, true); - expect(mockTelemetryAPI.request.calls.length).toBe(0); + expect(mockTelemetryAPI.request.calls.count()).toBe(0); }); }); @@ -613,20 +562,18 @@ define( it("updates displayed values from historical telemetry", function () { spyOn(controller, "updateView"); - controller.updateView.andCallThrough(); + controller.updateView.and.callThrough(); - mockTelemetryAPI.request.andReturn(Promise.resolve([{ + mockTelemetryAPI.request.and.returnValue(Promise.resolve([{ time: 100, value: testValue }])); controller.fetchHistoricalData(mockTelemetryObject); - waitsFor(function () { - return controller.digesting === false; - }); - - runs(function () { + return new Promise(function (resolve) { + mockScope.$digest.and.callFake(resolve); + }).then(function () { expect(controller.updateView).toHaveBeenCalled(); expect(controller.getElements()[0].value) .toEqual("Formatted " + testValue); @@ -634,7 +581,7 @@ define( }); it("selects an range value to display, if available", function () { - mockMetadata.valuesForHints.andReturn([ + mockMetadata.valuesForHints.and.returnValue([ { key: 'range', source: 'range' @@ -645,8 +592,8 @@ define( }); it("selects the first non-domain value to display, if no range available", function () { - mockMetadata.valuesForHints.andReturn([]); - mockMetadata.values.andReturn([ + mockMetadata.valuesForHints.and.returnValue([]); + mockMetadata.values.and.returnValue([ { key: 'domain', source: 'domain', @@ -667,17 +614,15 @@ define( }); it("reflects limit status", function () { - mockLimitEvaluator.evaluate.andReturn({cssClass: "alarm-a"}); + mockLimitEvaluator.evaluate.and.returnValue({cssClass: "alarm-a"}); controller.updateView(mockTelemetryObject, [{ time: 100, value: testValue }]); - waitsFor(function () { - return controller.digesting === false; - }); - - runs(function () { + return new Promise(function (resolve) { + mockScope.$digest.and.callFake(resolve); + }).then(function () { // Limit-based CSS classes should be available expect(controller.getElements()[0].cssClass).toEqual("alarm-a"); }); diff --git a/platform/features/layout/test/FixedDragHandleSpec.js b/platform/features/layout/test/FixedDragHandleSpec.js index 1d7d88f621..9e8daa2ac1 100644 --- a/platform/features/layout/test/FixedDragHandleSpec.js +++ b/platform/features/layout/test/FixedDragHandleSpec.js @@ -37,16 +37,16 @@ define( 'elementHandle', ['x', 'y','getGridSize'] ); - mockElementHandle.x.andReturn(6); - mockElementHandle.y.andReturn(8); - mockElementHandle.getGridSize.andReturn(TEST_GRID_SIZE); + mockElementHandle.x.and.returnValue(6); + mockElementHandle.y.and.returnValue(8); + mockElementHandle.getGridSize.and.returnValue(TEST_GRID_SIZE); mockFixedControl = jasmine.createSpyObj( 'fixedControl', ['updateSelectionStyle', 'mutate'] ); - mockFixedControl.updateSelectionStyle.andReturn(); - mockFixedControl.mutate.andReturn(); + mockFixedControl.updateSelectionStyle.and.returnValue(); + mockFixedControl.mutate.and.returnValue(); mockConfigPath = jasmine.createSpy('configPath'); @@ -80,7 +80,7 @@ define( expect(mockElementHandle.y).toHaveBeenCalledWith(7); // Should have called updateSelectionStyle once per continueDrag - expect(mockFixedControl.updateSelectionStyle.calls.length).toEqual(2); + expect(mockFixedControl.updateSelectionStyle.calls.count()).toEqual(2); // Finally, ending drag should mutate handle.endDrag(); diff --git a/platform/features/layout/test/FixedProxySpec.js b/platform/features/layout/test/FixedProxySpec.js index 609f005019..370a35e02e 100644 --- a/platform/features/layout/test/FixedProxySpec.js +++ b/platform/features/layout/test/FixedProxySpec.js @@ -37,7 +37,7 @@ define( mockDialogService = jasmine.createSpyObj('dialogService', ['getUserInput']); mockPromise = jasmine.createSpyObj('promise', ['then']); - mockQ.when.andReturn(mockPromise); + mockQ.when.and.returnValue(mockPromise); proxy = new FixedProxy(mockCallback, mockQ, mockDialogService); }); @@ -54,7 +54,7 @@ define( // Callback should not have been invoked yet expect(mockCallback).not.toHaveBeenCalled(); // Resolve the promise - mockPromise.then.mostRecentCall.args[0]({}); + mockPromise.then.calls.mostRecent().args[0]({}); // Should have fired the callback expect(mockCallback).toHaveBeenCalledWith({ type: "fixed.box", diff --git a/platform/features/layout/test/LayoutCompositionPolicySpec.js b/platform/features/layout/test/LayoutCompositionPolicySpec.js index e25dabdb84..19872ac267 100644 --- a/platform/features/layout/test/LayoutCompositionPolicySpec.js +++ b/platform/features/layout/test/LayoutCompositionPolicySpec.js @@ -45,14 +45,14 @@ define( mockCandidateObj = jasmine.createSpyObj('domainObj', [ 'getCapability' ]); - mockCandidateObj.getCapability.andReturn(mockCandidate); + mockCandidateObj.getCapability.and.returnValue(mockCandidate); - mockChild.getCapability.andReturn(mockContext); + mockChild.getCapability.and.returnValue(mockContext); - mockCandidate.instanceOf.andCallFake(function (t) { + mockCandidate.instanceOf.and.callFake(function (t) { return t === candidateType; }); - mockContext.instanceOf.andCallFake(function (t) { + mockContext.instanceOf.and.callFake(function (t) { return t === contextType; }); diff --git a/platform/features/layout/test/LayoutControllerSpec.js b/platform/features/layout/test/LayoutControllerSpec.js index 55d575bf1e..06d425064f 100644 --- a/platform/features/layout/test/LayoutControllerSpec.js +++ b/platform/features/layout/test/LayoutControllerSpec.js @@ -112,7 +112,7 @@ define( mockDomainObjectCapability = jasmine.createSpyObj('capability', ['inEditContext', 'listen'] ); - mockDomainObjectCapability.listen.andReturn(unlistenFunc); + mockDomainObjectCapability.listen.and.returnValue(unlistenFunc); mockCompositionCapability = mockPromise(mockCompositionObjects); @@ -132,12 +132,12 @@ define( 'off', 'get' ]); - mockSelection.get.andReturn(selectable); + mockSelection.get.and.returnValue(selectable); mockObjects = jasmine.createSpyObj('objects', [ 'get' ]); - mockObjects.get.andReturn(mockPromise(mockDomainObject("mockObject"))); + mockObjects.get.and.returnValue(mockPromise(mockDomainObject("mockObject"))); mockOpenMCT = { selection: mockSelection, objects: mockObjects @@ -147,17 +147,18 @@ define( $(document).find('body').append($element); spyOn($element[0], 'click'); - spyOn(mockScope.domainObject, "useCapability").andCallThrough(); + spyOn(mockScope.domainObject, "useCapability").and.callThrough(); controller = new LayoutController(mockScope, $element, mockOpenMCT); - spyOn(controller, "layoutPanels").andCallThrough(); + spyOn(controller, "layoutPanels").and.callThrough(); spyOn(controller, "commit"); - jasmine.Clock.useMock(); + jasmine.clock().install(); }); afterEach(function () { $element.remove(); + jasmine.clock().uninstall(); }); @@ -174,7 +175,7 @@ define( jasmine.any(Function) ); - mockScope.$on.calls[0].args[1](); + mockScope.$on.calls.all()[0].args[1](); expect(mockOpenMCT.selection.off).toHaveBeenCalledWith( 'change', @@ -192,7 +193,7 @@ define( }); it("Retrieves updated composition from composition capability", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); expect(mockScope.domainObject.useCapability).toHaveBeenCalledWith( "composition" ); @@ -208,11 +209,11 @@ define( secondCompositionCB; spyOn(mockCompositionCapability, "then"); - mockScope.$watchCollection.mostRecentCall.args[1](); - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); - firstCompositionCB = mockCompositionCapability.then.calls[0].args[0]; - secondCompositionCB = mockCompositionCapability.then.calls[1].args[0]; + firstCompositionCB = mockCompositionCapability.then.calls.all()[0].args[0]; + secondCompositionCB = mockCompositionCapability.then.calls.all()[1].args[0]; //Resolve promises in reverse order secondCompositionCB(secondMockCompositionObjects); @@ -226,7 +227,7 @@ define( it("provides styles for frames, from configuration", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); expect(controller.getFrameStyle("a")).toEqual({ top: "320px", left: "640px", @@ -241,7 +242,7 @@ define( var styleB, styleC; // b and c do not have configured positions - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); styleB = controller.getFrameStyle("b"); styleC = controller.getFrameStyle("c"); @@ -258,7 +259,7 @@ define( it("allows panels to be dragged", function () { // Populate scope - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); // Verify precondition expect(testConfiguration.panels.b).not.toBeDefined(); @@ -277,7 +278,7 @@ define( it("invokes commit after drag", function () { // Populate scope - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); // Do a drag controller.startDrag("b", [1, 1], [0, 0]); @@ -300,7 +301,7 @@ define( expect(testConfiguration.panels.d).not.toBeDefined(); // Notify that a drop occurred - mockScope.$on.mostRecentCall.args[1]( + mockScope.$on.calls.mostRecent().args[1]( mockEvent, 'd', { x: 300, y: 100 } @@ -315,7 +316,7 @@ define( mockEvent.defaultPrevented = true; // Notify that a drop occurred - mockScope.$on.mostRecentCall.args[1]( + mockScope.$on.calls.mostRecent().args[1]( mockEvent, 'd', { x: 300, y: 100 } @@ -330,8 +331,8 @@ define( testModel.layoutGrid = [1, 1]; // White-boxy; we know which watch is which - mockScope.$watch.calls[0].args[1](testModel.layoutGrid); - mockScope.$watchCollection.calls[0].args[1](testModel.composition); + mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid); + mockScope.$watchCollection.calls.all()[0].args[1](testModel.composition); styleB = controller.getFrameStyle("b"); @@ -345,7 +346,7 @@ define( // Start with a very small frame size testModel.layoutGrid = [1, 1]; - mockScope.$watch.calls[0].args[1](testModel.layoutGrid); + mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid); // Add a new object to the composition mockComposition = ["a", "b", "c", "d"]; @@ -353,7 +354,7 @@ define( mockCompositionCapability = mockPromise(mockCompositionObjects); // Notify that a drop occurred - mockScope.$on.mostRecentCall.args[1]( + mockScope.$on.calls.mostRecent().args[1]( mockEvent, 'd', { x: 300, y: 100 } @@ -369,14 +370,14 @@ define( it("updates positions of existing objects on a drop", function () { var oldStyle; - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); oldStyle = controller.getFrameStyle("b"); expect(oldStyle).toBeDefined(); // ...drop event... - mockScope.$on.mostRecentCall + mockScope.$on.calls.mostRecent() .args[1](mockEvent, 'b', { x: 300, y: 100 }); expect(controller.getFrameStyle("b")) @@ -384,16 +385,16 @@ define( }); it("allows objects to be selected", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); var childObj = mockCompositionObjects[0]; selectable[0].context.oldItem = childObj; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); expect(controller.selected(childObj)).toBe(true); }); it("prevents event bubbling while drag is in progress", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); var childObj = mockCompositionObjects[0]; // Do a drag @@ -407,57 +408,57 @@ define( expect(mockEvent.stopPropagation).toHaveBeenCalled(); // Shoud be able to select another object when dragging is done. - jasmine.Clock.tick(0); - mockEvent.stopPropagation.reset(); + jasmine.clock().tick(0); + mockEvent.stopPropagation.calls.reset(); controller.bypassSelection(mockEvent); expect(mockEvent.stopPropagation).not.toHaveBeenCalled(); }); it("shows frames by default", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); expect(controller.hasFrame(mockCompositionObjects[0])).toBe(true); }); it("hyperlinks hide frame by default", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); expect(controller.hasFrame(mockCompositionObjects[1])).toBe(false); }); it("selects the parent object when selected object is removed", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); var childObj = mockCompositionObjects[0]; selectable[0].context.oldItem = childObj; - mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); + mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable); var composition = ["b", "c"]; - mockScope.$watchCollection.mostRecentCall.args[1](composition); + mockScope.$watchCollection.calls.mostRecent().args[1](composition); expect($element[0].click).toHaveBeenCalled(); }); it("allows objects to be drilled-in only when editing", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); var childObj = mockCompositionObjects[0]; - childObj.getCapability().inEditContext.andReturn(false); + childObj.getCapability().inEditContext.and.returnValue(false); controller.drill(mockEvent, childObj); expect(controller.isDrilledIn(childObj)).toBe(false); }); it("allows objects to be drilled-in only if it has sub objects", function () { - mockScope.$watchCollection.mostRecentCall.args[1](); + mockScope.$watchCollection.calls.mostRecent().args[1](); var childObj = mockCompositionObjects[1]; - childObj.getCapability().inEditContext.andReturn(true); + childObj.getCapability().inEditContext.and.returnValue(true); controller.drill(mockEvent, childObj); expect(controller.isDrilledIn(childObj)).toBe(false); }); it("selects a newly-dropped object", function () { - mockScope.$on.mostRecentCall.args[1]( + mockScope.$on.calls.mostRecent().args[1]( mockEvent, 'd', { x: 300, y: 100 } @@ -469,7 +470,7 @@ define( spyOn(testElement[0], 'click'); controller.selectIfNew('some-id', childObj); - jasmine.Clock.tick(0); + jasmine.clock().tick(0); expect(testElement[0].click).toHaveBeenCalled(); }); diff --git a/platform/features/layout/test/MCTTriggerModalSpec.js b/platform/features/layout/test/MCTTriggerModalSpec.js index 9538a6467d..3bf4088821 100644 --- a/platform/features/layout/test/MCTTriggerModalSpec.js +++ b/platform/features/layout/test/MCTTriggerModalSpec.js @@ -38,10 +38,10 @@ define([ 'hasClass', 'parent' ]); - elem.hasClass.andCallFake(function (className) { + elem.hasClass.and.callFake(function (className) { return classes.indexOf(className) !== -1; }); - elem.parent.andReturn(parentEl); + elem.parent.and.returnValue(parentEl); var div = document.createElement('div'); div.className = classes.join(' '); parentEl[0].appendChild(div); @@ -70,10 +70,10 @@ define([ for (var i = 0; i < 5; i++) { child = makeElement([], child); } - $element.parent.andReturn(child); + $element.parent.and.returnValue(child); $document = [jasmine.createSpyObj('document', ['createElement'])]; $document[0].body = document.createElement('div'); - $document[0].createElement.andCallFake(function (tag) { + $document[0].createElement.and.callFake(function (tag) { return document.createElement(tag); }); @@ -102,7 +102,7 @@ define([ '$destroy', jasmine.any(Function) ); - $scope.$on.mostRecentCall.args[1](); + $scope.$on.calls.mostRecent().args[1](); expect($element.off).toHaveBeenCalledWith( 'click', jasmine.any(Function) @@ -113,7 +113,7 @@ define([ [ 'a.close', 'a.t-done', '.abs.blocker' ].forEach(function (selector) { - $element.on.mostRecentCall.args[1](); + $element.on.calls.mostRecent().args[1](); var container = $document[0].body.querySelector('.t-contents'); expect(container.children[0]).toBe(frame[0]); expect(layoutContainer.children[0]).not.toBe(frame[0]); diff --git a/platform/features/layout/test/elements/ElementFactorySpec.js b/platform/features/layout/test/elements/ElementFactorySpec.js index 9f1b6dfdf5..e879d1e8a7 100644 --- a/platform/features/layout/test/elements/ElementFactorySpec.js +++ b/platform/features/layout/test/elements/ElementFactorySpec.js @@ -42,8 +42,8 @@ define( ['then'] ); - mockDialogService.getUserInput.andReturn(mockPromise); - mockPromise.then.andReturn(mockPromise); + mockDialogService.getUserInput.and.returnValue(mockPromise); + mockPromise.then.and.returnValue(mockPromise); factory = new ElementFactory(mockDialogService); }); diff --git a/platform/features/layout/test/elements/LineHandleSpec.js b/platform/features/layout/test/elements/LineHandleSpec.js index d1465f8f89..dae09a10ac 100644 --- a/platform/features/layout/test/elements/LineHandleSpec.js +++ b/platform/features/layout/test/elements/LineHandleSpec.js @@ -39,7 +39,7 @@ define( useGrid: true }; mockElementProxy = jasmine.createSpyObj('elementProxy', ['getGridSize']); - mockElementProxy.getGridSize.andReturn(TEST_GRID_SIZE); + mockElementProxy.getGridSize.and.returnValue(TEST_GRID_SIZE); handle = new LineHandle(testElement, mockElementProxy, 'x', 'y', 'x2', 'y2'); }); diff --git a/platform/features/layout/test/elements/ResizeHandleSpec.js b/platform/features/layout/test/elements/ResizeHandleSpec.js index 526df95813..f7fda158a1 100644 --- a/platform/features/layout/test/elements/ResizeHandleSpec.js +++ b/platform/features/layout/test/elements/ResizeHandleSpec.js @@ -46,9 +46,9 @@ define( 'getMinWidth', 'getMinHeight' ]); - mockElementProxy.getGridSize.andReturn(TEST_GRID_SIZE); - mockElementProxy.getMinWidth.andReturn(TEST_MIN_WIDTH); - mockElementProxy.getMinHeight.andReturn(TEST_MIN_HEIGHT); + mockElementProxy.getGridSize.and.returnValue(TEST_GRID_SIZE); + mockElementProxy.getMinWidth.and.returnValue(TEST_MIN_WIDTH); + mockElementProxy.getMinHeight.and.returnValue(TEST_MIN_HEIGHT); handle = new ResizeHandle( mockElementProxy, diff --git a/platform/features/layout/test/elements/UnitAccessorMutatorSpec.js b/platform/features/layout/test/elements/UnitAccessorMutatorSpec.js index d5cf38ecd0..a5378d9d81 100644 --- a/platform/features/layout/test/elements/UnitAccessorMutatorSpec.js +++ b/platform/features/layout/test/elements/UnitAccessorMutatorSpec.js @@ -72,11 +72,11 @@ define( uAM = new UnitAccessorMutator(mockElementProxy); uAMLine = new UnitAccessorMutator(mockLineProxy); - mockElementProxy.getMinWidth.andReturn(1); - mockElementProxy.getMinHeight.andReturn(1); + mockElementProxy.getMinWidth.and.returnValue(1); + mockElementProxy.getMinHeight.and.returnValue(1); - mockLineProxy.getMinWidth.andReturn(1); - mockLineProxy.getMinHeight.andReturn(1); + mockLineProxy.getMinWidth.and.returnValue(1); + mockLineProxy.getMinHeight.and.returnValue(1); }); it("allows access to useGrid", function () { diff --git a/platform/features/listview/test/controllers/ListViewControllerSpec.js b/platform/features/listview/test/controllers/ListViewControllerSpec.js index d4b3638f5f..7d95981ef3 100644 --- a/platform/features/listview/test/controllers/ListViewControllerSpec.js +++ b/platform/features/listview/test/controllers/ListViewControllerSpec.js @@ -28,11 +28,12 @@ define( unlistenFunc, domainObject, childObject, - controller, childModel, typeCapability, mutationCapability, - formatService; + formatService, + compositionPromise, + controller; beforeEach(function () { unlistenFunc = jasmine.createSpy("unlisten"); @@ -41,17 +42,17 @@ define( "mutationCapability", ["listen"] ); - mutationCapability.listen.andReturn(unlistenFunc); + mutationCapability.listen.and.returnValue(unlistenFunc); formatService = jasmine.createSpyObj( "formatService", ["getFormat"] ); - formatService.getFormat.andReturn(jasmine.createSpyObj( + formatService.getFormat.and.returnValue(jasmine.createSpyObj( 'utc', ["format"] )); - formatService.getFormat().format.andCallFake(function (v) { + formatService.getFormat().format.and.callFake(function (v) { return "formatted " + v; }); @@ -59,8 +60,8 @@ define( "typeCapability", ["getCssClass", "getName"] ); - typeCapability.getCssClass.andReturn("icon-folder"); - typeCapability.getName.andReturn("Folder"); + typeCapability.getCssClass.and.returnValue("icon-folder"); + typeCapability.getName.and.returnValue("Folder"); childModel = jasmine.createSpyObj( @@ -75,13 +76,11 @@ define( "childObject", ["getModel", "getCapability"] ); - childObject.getModel.andReturn( + childObject.getModel.and.returnValue( childModel ); - // childObject.getCapability.andReturn( - // typeCapability - // ); - childObject.getCapability.andCallFake(function (arg) { + + childObject.getCapability.and.callFake(function (arg) { if (arg === 'location') { return ''; } else if (arg === 'type') { @@ -94,25 +93,21 @@ define( "domainObject", ["getCapability", "useCapability"] ); - domainObject.useCapability.andReturn( - Promise.resolve([childObject]) - ); - domainObject.getCapability.andReturn( + compositionPromise = Promise.resolve([childObject]); + domainObject.useCapability.and.returnValue(compositionPromise); + domainObject.getCapability.and.returnValue( mutationCapability ); - scope = jasmine.createSpyObj( "$scope", ["$on", "$apply"] ); scope.domainObject = domainObject; - controller = new ListViewController(scope, formatService); + controller = new ListViewController(scope, formatService); - waitsFor(function () { - return scope.children; - }); + return compositionPromise; }); it("uses the UTC time format", function () { @@ -120,37 +115,39 @@ define( }); it("updates the view", function () { - expect(scope.children[0]).toEqual( - { - icon: "icon-folder", - title: "Battery Charge Status", - type: "Folder", - persisted: formatService.getFormat('utc') - .format(childModel.persisted), - modified: formatService.getFormat('utc') - .format(childModel.modified), - asDomainObject: childObject, - location: '' - } - ); + var child = scope.children[0]; + var testChild = { + icon: "icon-folder", + title: "Battery Charge Status", + type: "Folder", + persisted: formatService.getFormat('utc') + .format(childModel.persisted), + modified: formatService.getFormat('utc') + .format(childModel.modified), + asDomainObject: childObject, + location: '', + action: childObject.getCapability('action') + }; + + expect(child).toEqual(testChild); }); it("updates the scope when mutation occurs", function () { - domainObject.useCapability.andReturn( - Promise.resolve([]) - ); + var applyPromise = new Promise(function (resolve) { + scope.$apply.and.callFake(resolve); + }); + + domainObject.useCapability.and.returnValue(Promise.resolve([])); expect(mutationCapability.listen).toHaveBeenCalledWith(jasmine.any(Function)); - mutationCapability.listen.mostRecentCall.args[0](); - waitsFor(function () { - return scope.children.length !== 1; - }); - runs(function () { + mutationCapability.listen.calls.mostRecent().args[0](); + + return applyPromise.then(function () { expect(scope.children.length).toEqual(0); + expect(scope.$apply).toHaveBeenCalled(); }); - expect(scope.$apply).toHaveBeenCalled(); }); it("releases listeners on $destroy", function () { expect(scope.$on).toHaveBeenCalledWith('$destroy', jasmine.any(Function)); - scope.$on.mostRecentCall.args[1](); + scope.$on.calls.mostRecent().args[1](); expect(unlistenFunc).toHaveBeenCalled(); }); diff --git a/platform/features/listview/test/directives/MCTGestureSpec.js b/platform/features/listview/test/directives/MCTGestureSpec.js index d84842f515..7ea8571b77 100644 --- a/platform/features/listview/test/directives/MCTGestureSpec.js +++ b/platform/features/listview/test/directives/MCTGestureSpec.js @@ -39,7 +39,7 @@ define( "gestureService", ["attachGestures"] ); - gestureService.attachGestures.andReturn( + gestureService.attachGestures.and.returnValue( attachedGesture ); mctGesture = MCTGesture(gestureService); @@ -77,7 +77,7 @@ define( '$destroy', jasmine.any(Function) ); - scope.$on.mostRecentCall.args[1](); + scope.$on.calls.mostRecent().args[1](); expect(attachedGesture.destroy).toHaveBeenCalled(); }); diff --git a/platform/features/pages/test/EmbeddedPageControllerSpec.js b/platform/features/pages/test/EmbeddedPageControllerSpec.js index 0aa21cc3dd..e561786b49 100644 --- a/platform/features/pages/test/EmbeddedPageControllerSpec.js +++ b/platform/features/pages/test/EmbeddedPageControllerSpec.js @@ -34,7 +34,7 @@ define( ["trustAsResourceUrl"] ); - mockSCE.trustAsResourceUrl.andCallFake(function (v) { + mockSCE.trustAsResourceUrl.and.callFake(function (v) { return v; }); diff --git a/platform/features/table/test/TableConfigurationSpec.js b/platform/features/table/test/TableConfigurationSpec.js index f74575d255..54b6efb8c7 100644 --- a/platform/features/table/test/TableConfigurationSpec.js +++ b/platform/features/table/test/TableConfigurationSpec.js @@ -38,8 +38,8 @@ define( ['getModel', 'useCapability', 'getCapability', 'hasCapability'] ); mockModel = {}; - mockDomainObject.getModel.andReturn(mockModel); - mockDomainObject.getCapability.andCallFake(function (name) { + mockDomainObject.getModel.and.returnValue(mockModel); + mockDomainObject.getCapability.and.callFake(function (name) { return name === 'editor' && { isEditContextRoot: function () { return true; @@ -53,7 +53,7 @@ define( mockAPI = { telemetry: mockTelemetryAPI }; - mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) { + mockTelemetryAPI.getValueFormatter.and.callFake(function (metadata) { var formatter = jasmine.createSpyObj( 'telemetryFormatter:' + metadata.key, [ @@ -64,8 +64,8 @@ define( var getter = function (datum) { return datum[metadata.key]; }; - formatter.format.andCallFake(getter); - formatter.parse.andCallFake(getter); + formatter.format.and.callFake(getter); + formatter.parse.and.callFake(getter); return formatter; }); diff --git a/platform/features/table/test/TelemetryCollectionSpec.js b/platform/features/table/test/TelemetryCollectionSpec.js index 42ad08fd70..6331b09ebb 100644 --- a/platform/features/table/test/TelemetryCollectionSpec.js +++ b/platform/features/table/test/TelemetryCollectionSpec.js @@ -84,7 +84,7 @@ define( it("discards telemetry data with a time stamp " + "before specified start bound", function () { - var discarded = discardedCallback.mostRecentCall.args[0]; + var discarded = discardedCallback.calls.mostRecent().args[0]; // Expect 5 because as an optimization, the TelemetryCollection // will not consider telemetry values that exceed the upper diff --git a/platform/features/table/test/controllers/MCTTableControllerSpec.js b/platform/features/table/test/controllers/MCTTableControllerSpec.js index 544a8fc5cc..a6ef4cac5d 100644 --- a/platform/features/table/test/controllers/MCTTableControllerSpec.js +++ b/platform/features/table/test/controllers/MCTTableControllerSpec.js @@ -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); }); }); diff --git a/platform/features/table/test/controllers/TableOptionsControllerSpec.js b/platform/features/table/test/controllers/TableOptionsControllerSpec.js index bb8f112d54..891c933f43 100644 --- a/platform/features/table/test/controllers/TableOptionsControllerSpec.js +++ b/platform/features/table/test/controllers/TableOptionsControllerSpec.js @@ -40,8 +40,8 @@ define( 'getCapability', 'getModel' ]); - mockDomainObject.getCapability.andReturn(mockCapability); - mockDomainObject.getModel.andReturn({}); + mockDomainObject.getCapability.and.returnValue(mockCapability); + mockDomainObject.getModel.and.returnValue({}); mockScope = jasmine.createSpyObj('scope', [ '$watchCollection', @@ -61,12 +61,12 @@ define( var unlistenFunc = jasmine.createSpy("unlisten"); controller.listeners.push(unlistenFunc); expect(mockScope.$on).toHaveBeenCalledWith('$destroy', jasmine.any(Function)); - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); expect(unlistenFunc).toHaveBeenCalled(); }); it('Registers a listener for mutation events on the object', function () { - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); expect(mockCapability.listen).toHaveBeenCalled(); }); diff --git a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js index db2f2f5876..2b928f999c 100644 --- a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js +++ b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js @@ -43,7 +43,7 @@ define( mockBounds; 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]; } @@ -60,8 +60,8 @@ define( "off", "timeSystem" ]); - mockConductor.bounds.andReturn(mockBounds); - mockConductor.clock.andReturn(undefined); + mockConductor.bounds.and.returnValue(mockBounds); + mockConductor.clock.and.returnValue(undefined); mockDomainObject = jasmine.createSpyObj("domainObject", [ "getModel", @@ -69,9 +69,9 @@ define( "useCapability", "hasCapability" ]); - mockDomainObject.getModel.andReturn({}); - mockDomainObject.getId.andReturn("mockId"); - mockDomainObject.useCapability.andReturn(true); + mockDomainObject.getModel.and.returnValue({}); + mockDomainObject.getId.and.returnValue("mockId"); + mockDomainObject.useCapability.and.returnValue(true); mockCompositionAPI = jasmine.createSpyObj("compositionAPI", [ "get" @@ -81,7 +81,7 @@ define( "observe" ]); unobserve = jasmine.createSpy("unobserve"); - mockObjectAPI.observe.andReturn(unobserve); + mockObjectAPI.observe.and.returnValue(unobserve); mockScope = jasmine.createSpyObj("scope", [ "$on", @@ -99,9 +99,14 @@ define( "limitEvaluator", "getValueFormatter" ]); - mockTelemetryAPI.commonValuesForHints.andReturn([]); - mockTelemetryAPI.request.andReturn(Promise.resolve([])); - mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) { + mockTelemetryAPI.commonValuesForHints.and.returnValue([]); + mockTelemetryAPI.request.and.returnValue(Promise.resolve([])); + mockTelemetryAPI.getMetadata.and.returnValue({ + values: function () { + return []; + } + }); + mockTelemetryAPI.getValueFormatter.and.callFake(function (metadata) { var formatter = jasmine.createSpyObj( 'telemetryFormatter:' + metadata.key, [ @@ -112,19 +117,15 @@ define( var getter = function (datum) { return datum[metadata.key]; }; - formatter.format.andCallFake(getter); - formatter.parse.andCallFake(getter); + formatter.format.and.callFake(getter); + formatter.parse.and.callFake(getter); return formatter; }); - mockTelemetryAPI.getMetadata.andReturn({ - values: function () { - return []; - } - }); - mockTelemetryAPI.isTelemetryObject.andReturn(false); + + mockTelemetryAPI.isTelemetryObject.and.returnValue(false); mockTimeout = jasmine.createSpy("timeout"); - mockTimeout.andReturn(1); // Return something + mockTimeout.and.returnValue(1); // Return something mockTimeout.cancel = jasmine.createSpy("cancel"); mockAPI = { @@ -141,7 +142,7 @@ define( controller.registerChangeListeners(); }); it('object mutation', function () { - var calledObject = mockObjectAPI.observe.mostRecentCall.args[0]; + var calledObject = mockObjectAPI.observe.calls.mostRecent().args[0]; expect(mockObjectAPI.observe).toHaveBeenCalled(); expect(calledObject.identifier.key).toEqual(mockDomainObject.getId()); @@ -197,13 +198,13 @@ define( }; unsubscribe = jasmine.createSpy("unsubscribe"); - mockTelemetryAPI.subscribe.andReturn(unsubscribe); + mockTelemetryAPI.subscribe.and.returnValue(unsubscribe); mockChildren = [mockTelemetryObject]; - mockComposition.load.andReturn(Promise.resolve(mockChildren)); - mockCompositionAPI.get.andReturn(mockComposition); + mockComposition.load.and.returnValue(Promise.resolve(mockChildren)); + mockCompositionAPI.get.and.returnValue(mockComposition); - mockTelemetryAPI.isTelemetryObject.andCallFake(function (obj) { + mockTelemetryAPI.isTelemetryObject.and.callFake(function (obj) { return obj.identifier.key === mockTelemetryObject.identifier.key; }); @@ -211,28 +212,13 @@ define( }); it('fetches historical data for the time period specified by the conductor bounds', function () { - controller.getData().then(function () { - done = true; - }); - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds); }); }); it('unsubscribes on view destruction', function () { - controller.getData().then(function () { - done = true; - }); - - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { var destroy = getCallback(mockScope.$on, "$destroy"); destroy(); @@ -240,40 +226,19 @@ define( }); }); it('fetches historical data for the time period specified by the conductor bounds', function () { - controller.getData().then(function () { - done = true; - }); - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds); }); }); it('fetches data for, and subscribes to parent object if it is a telemetry object', function () { - controller.getData().then(function () { - done = true; - }); - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {}); expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object)); }); }); it('fetches data for, and subscribes to parent object if it is a telemetry object', function () { - controller.getData().then(function () { - done = true; - }); - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {}); expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object)); }); @@ -289,9 +254,9 @@ define( {name: "child 4"} ]; mockChildren = mockChildren.concat(mockTelemetryChildren); - mockComposition.load.andReturn(Promise.resolve(mockChildren)); + mockComposition.load.and.returnValue(Promise.resolve(mockChildren)); - mockTelemetryAPI.isTelemetryObject.andCallFake(function (object) { + mockTelemetryAPI.isTelemetryObject.and.callFake(function (object) { if (object === mockTelemetryObject) { return false; } else { @@ -299,15 +264,7 @@ define( } }); - controller.getData().then(function () { - done = true; - }); - - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { + return controller.getData().then(function () { mockTelemetryChildren.forEach(function (child) { expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(child, jasmine.any(Function), {}); }); @@ -364,13 +321,13 @@ define( key: "column1" }; - mockTelemetryAPI.commonValuesForHints.andCallFake(function (metadata, hints) { + mockTelemetryAPI.commonValuesForHints.and.callFake(function (metadata, hints) { if (_.eq(hints, ["domain"])) { return domainMetadata; } }); - mockTelemetryAPI.getMetadata.andReturn({ + mockTelemetryAPI.getMetadata.and.returnValue({ values: function () { return allMetadata; } @@ -409,21 +366,21 @@ define( "column3": 9 } ]; + controller.batchSize = 2; - mockTelemetryAPI.request.andReturn(Promise.resolve(mockHistoricalData)); + mockTelemetryAPI.request.and.returnValue(Promise.resolve(mockHistoricalData)); controller.getHistoricalData([mockDomainObject]); - waitsFor(function () { - return !!controller.timeoutHandle; - }, "first batch to be processed", 100); - - runs(function () { - //Verify that timeout is being used to yield process - expect(mockTimeout).toHaveBeenCalled(); - mockTimeout.mostRecentCall.args[0](); - expect(mockTimeout.calls.length).toBe(2); - mockTimeout.mostRecentCall.args[0](); + return new Promise(function (resolve) { + mockTimeout.and.callFake(function () { + resolve(); + }); + }).then(function () { + mockTimeout.calls.mostRecent().args[0](); + expect(mockTimeout.calls.count()).toBe(2); + mockTimeout.calls.mostRecent().args[0](); expect(mockScope.rows.length).toBe(3); + }); }); }); @@ -435,7 +392,7 @@ define( {"column3": "value 3"} ]; - spyOn(controller.telemetry, "on").andCallThrough(); + spyOn(controller.telemetry, "on").and.callThrough(); controller.registerChangeListeners(); expect(controller.telemetry.on).toHaveBeenCalledWith("discarded", jasmine.any(Function)); @@ -453,10 +410,10 @@ define( mockScope.rows = [{ a: -1 }]; expectedRows = mockScope.rows.concat(testRows); - spyOn(controller.telemetry, "on").andCallThrough(); + spyOn(controller.telemetry, "on").and.callThrough(); controller.registerChangeListeners(); - controller.telemetry.on.calls.forEach(function (call) { + controller.telemetry.on.calls.all().forEach(function (call) { if (call.args[0] === 'added') { call.args[1](testRows); } diff --git a/platform/features/timeline/test/actions/CompositionColumnSpec.js b/platform/features/timeline/test/actions/CompositionColumnSpec.js index c697bc743b..6c753a6616 100644 --- a/platform/features/timeline/test/actions/CompositionColumnSpec.js +++ b/platform/features/timeline/test/actions/CompositionColumnSpec.js @@ -54,7 +54,7 @@ define( ['getId', 'getModel', 'getCapability'] ); testModel = { composition: TEST_IDS }; - mockDomainObject.getModel.andReturn(testModel); + mockDomainObject.getModel.and.returnValue(testModel); }); it("returns a corresponding value from the map", function () { diff --git a/platform/features/timeline/test/actions/ExportTimelineAsCSVActionSpec.js b/platform/features/timeline/test/actions/ExportTimelineAsCSVActionSpec.js index b59ffbf606..e0b492647c 100644 --- a/platform/features/timeline/test/actions/ExportTimelineAsCSVActionSpec.js +++ b/platform/features/timeline/test/actions/ExportTimelineAsCSVActionSpec.js @@ -32,7 +32,8 @@ define( mockType, testContext, testType, - action; + action, + actionPromise; beforeEach(function () { mockDomainObject = jasmine.createSpyObj( @@ -60,11 +61,11 @@ define( ['dismiss'] ); - mockNotificationService.notify.andReturn(mockNotification); + mockNotificationService.notify.and.returnValue(mockNotification); - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andReturn(mockType); - mockType.instanceOf.andCallFake(function (type) { + mockDomainObject.hasCapability.and.returnValue(true); + mockDomainObject.getCapability.and.returnValue(mockType); + mockType.instanceOf.and.callFake(function (type) { return type === testType; }); @@ -92,14 +93,12 @@ define( }); describe("when performed", function () { - var testPromise, - mockCallback; + var testPromise; beforeEach(function () { - mockCallback = jasmine.createSpy('callback'); // White-boxy; we know most work is delegated // to the associated Task, so stub out that interaction. - spyOn(action.task, "run").andCallFake(function () { + spyOn(action.task, "run").and.callFake(function () { return new Promise(function (resolve, reject) { testPromise = { resolve: resolve, @@ -107,7 +106,7 @@ define( }; }); }); - action.perform().then(mockCallback); + actionPromise = action.perform(); }); it("shows a notification", function () { @@ -122,9 +121,7 @@ define( describe("and completed", function () { beforeEach(function () { testPromise.resolve(); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); + return actionPromise; }); it("dismisses the displayed notification", function () { @@ -144,9 +141,8 @@ define( beforeEach(function () { testError = { someProperty: "some value" }; testPromise.reject(testError); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); + + return actionPromise; }); it("dismisses the displayed notification", function () { diff --git a/platform/features/timeline/test/actions/ExportTimelineAsCSVTaskSpec.js b/platform/features/timeline/test/actions/ExportTimelineAsCSVTaskSpec.js index 14a11b46e7..50723c8dc8 100644 --- a/platform/features/timeline/test/actions/ExportTimelineAsCSVTaskSpec.js +++ b/platform/features/timeline/test/actions/ExportTimelineAsCSVTaskSpec.js @@ -47,8 +47,8 @@ define( ] ); - mockDomainObject.getId.andReturn('mock'); - mockDomainObject.getModel.andReturn({}); + mockDomainObject.getId.and.returnValue('mock'); + mockDomainObject.getModel.and.returnValue({}); task = new ExportTimelineAsCSVTask( mockExportService, @@ -58,14 +58,9 @@ define( }); describe("when run", function () { - var mockCallback; beforeEach(function () { - mockCallback = jasmine.createSpy('callback'); - task.run().then(mockCallback); - waitsFor(function () { - return mockCallback.calls.length > 0; - }); + return task.run(); }); it("exports to CSV", function () { diff --git a/platform/features/timeline/test/actions/IdColumnSpec.js b/platform/features/timeline/test/actions/IdColumnSpec.js index 1201dbaba9..c7df5894d4 100644 --- a/platform/features/timeline/test/actions/IdColumnSpec.js +++ b/platform/features/timeline/test/actions/IdColumnSpec.js @@ -46,7 +46,7 @@ define( 'domainObject', ['getId', 'getModel', 'getCapability'] ); - mockDomainObject.getId.andReturn(testId); + mockDomainObject.getId.and.returnValue(testId); }); it("provides a value mapped from domain object's identifier", function () { diff --git a/platform/features/timeline/test/actions/MetadataColumnSpec.js b/platform/features/timeline/test/actions/MetadataColumnSpec.js index f1eaa8d594..97b604ba8e 100644 --- a/platform/features/timeline/test/actions/MetadataColumnSpec.js +++ b/platform/features/timeline/test/actions/MetadataColumnSpec.js @@ -54,7 +54,7 @@ define( testIndex = 1; testMetadata[testIndex].name = testName; - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return (c === 'metadata') && testMetadata; }); }); diff --git a/platform/features/timeline/test/actions/ModeColumnSpec.js b/platform/features/timeline/test/actions/ModeColumnSpec.js index 647ffd7eeb..d2c340f658 100644 --- a/platform/features/timeline/test/actions/ModeColumnSpec.js +++ b/platform/features/timeline/test/actions/ModeColumnSpec.js @@ -58,7 +58,7 @@ define( modes: TEST_IDS } }; - mockDomainObject.getModel.andReturn(testModel); + mockDomainObject.getModel.and.returnValue(testModel); }); it("returns a corresponding value from the map", function () { diff --git a/platform/features/timeline/test/actions/TimelineColumnizerSpec.js b/platform/features/timeline/test/actions/TimelineColumnizerSpec.js index 89eb3393f7..72eca01a9f 100644 --- a/platform/features/timeline/test/actions/TimelineColumnizerSpec.js +++ b/platform/features/timeline/test/actions/TimelineColumnizerSpec.js @@ -39,9 +39,9 @@ define( 'getModel' ] ); - mockDomainObject.getId.andReturn('id-' + index); - mockDomainObject.getModel.andReturn(model); - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.getId.and.returnValue('id-' + index); + mockDomainObject.getModel.and.returnValue(model); + mockDomainObject.useCapability.and.callFake(function (c) { return c === 'metadata' && []; }); return mockDomainObject; @@ -64,14 +64,14 @@ define( { } ].map(makeMockDomainObject); - mockDomainObjects[1].hasCapability.andCallFake(function (c) { + mockDomainObjects[1].hasCapability.and.callFake(function (c) { return c === 'timespan'; }); - mockDomainObjects[1].useCapability.andCallFake(function (c) { + mockDomainObjects[1].useCapability.and.callFake(function (c) { return c === 'timespan' ? Promise.resolve(mockTimespan) : c === 'metadata' ? [] : undefined; }); - mockDomainObjects[2].useCapability.andCallFake(function (c) { + mockDomainObjects[2].useCapability.and.callFake(function (c) { return c === 'metadata' && testMetadata; }); @@ -82,12 +82,9 @@ define( var rows; beforeEach(function () { - exporter.rows().then(function (r) { + return exporter.rows().then(function (r) { rows = r; }); - waitsFor(function () { - return rows !== undefined; - }); }); diff --git a/platform/features/timeline/test/actions/TimelineTraverserSpec.js b/platform/features/timeline/test/actions/TimelineTraverserSpec.js index d2ef9caa3f..804df2b6e8 100644 --- a/platform/features/timeline/test/actions/TimelineTraverserSpec.js +++ b/platform/features/timeline/test/actions/TimelineTraverserSpec.js @@ -43,17 +43,17 @@ define([ mockRelationships, model = testModels[id]; - mockDomainObject.getId.andReturn(id); - mockDomainObject.getModel.andReturn(model); + mockDomainObject.getId.and.returnValue(id); + mockDomainObject.getModel.and.returnValue(model); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return c === 'composition' ? !!model.composition : c === 'relationship' ? !!model.relationships : false; }); if (!!model.composition) { - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return c === 'composition' && Promise.resolve(model.composition.map(function (cid) { return mockDomainObjects[cid]; @@ -66,13 +66,13 @@ define([ 'relationship', ['getRelatedObjects'] ); - mockRelationships.getRelatedObjects.andCallFake(function (k) { + mockRelationships.getRelatedObjects.and.callFake(function (k) { var ids = model.relationships[k] || []; return Promise.resolve(ids.map(function (objId) { return mockDomainObjects[objId]; })); }); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return c === 'relationship' && mockRelationships; }); } @@ -105,12 +105,9 @@ define([ } beforeEach(function () { - traverser.buildObjectList().then(function (objectList) { + return traverser.buildObjectList().then(function (objectList) { objects = objectList; }); - waitsFor(function () { - return objects !== undefined; - }); }); it("includes the object originally passed in", function () { diff --git a/platform/features/timeline/test/actions/TimespanColumnSpec.js b/platform/features/timeline/test/actions/TimespanColumnSpec.js index c364292ef5..7fb6331f35 100644 --- a/platform/features/timeline/test/actions/TimespanColumnSpec.js +++ b/platform/features/timeline/test/actions/TimespanColumnSpec.js @@ -42,12 +42,12 @@ define( 'domainObject', ['useCapability', 'hasCapability'] ); - mockTimespan.getStart.andReturn(testTimes.start); - mockTimespan.getEnd.andReturn(testTimes.end); - mockDomainObject.useCapability.andCallFake(function (c) { + mockTimespan.getStart.and.returnValue(testTimes.start); + mockTimespan.getEnd.and.returnValue(testTimes.end); + mockDomainObject.useCapability.and.callFake(function (c) { return c === 'timespan' && Promise.resolve(mockTimespan); }); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return c === 'timespan'; }); }); @@ -71,12 +71,9 @@ define( beforeEach(function () { value = undefined; testFormatter = new TimelineFormatter(); - column.value(mockDomainObject).then(function (v) { + return column.value(mockDomainObject).then(function (v) { value = v; }); - waitsFor(function () { - return value !== undefined; - }); }); it("returns a formatted " + bound + " time", function () { diff --git a/platform/features/timeline/test/capabilities/ActivityTimespanCapabilitySpec.js b/platform/features/timeline/test/capabilities/ActivityTimespanCapabilitySpec.js index d62f3392bf..3ef068270c 100644 --- a/platform/features/timeline/test/capabilities/ActivityTimespanCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/ActivityTimespanCapabilitySpec.js @@ -44,8 +44,8 @@ define( ['getModel', 'getCapability'] ); - mockQ.when.andCallFake(asPromise); - mockDomainObject.getModel.andReturn({ + mockQ.when.and.callFake(asPromise); + mockDomainObject.getModel.and.returnValue({ start: { timestamp: 42000, epoch: "TEST" diff --git a/platform/features/timeline/test/capabilities/ActivityTimespanSpec.js b/platform/features/timeline/test/capabilities/ActivityTimespanSpec.js index e9acf004d9..88f13a4289 100644 --- a/platform/features/timeline/test/capabilities/ActivityTimespanSpec.js +++ b/platform/features/timeline/test/capabilities/ActivityTimespanSpec.js @@ -47,7 +47,7 @@ define( // not intended usage.) mutatorModel = JSON.parse(JSON.stringify(testModel)); mockMutation = jasmine.createSpyObj("mutation", ["mutate"]); - mockMutation.mutate.andCallFake(function (mutator) { + mockMutation.mutate.and.callFake(function (mutator) { mutator(mutatorModel); }); timespan = new ActivityTimespan(testModel, mockMutation); diff --git a/platform/features/timeline/test/capabilities/CostCapabilitySpec.js b/platform/features/timeline/test/capabilities/CostCapabilitySpec.js index a71d744599..239e08e312 100644 --- a/platform/features/timeline/test/capabilities/CostCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/CostCapabilitySpec.js @@ -42,7 +42,7 @@ define( } }; - mockDomainObject.getModel.andReturn(testModel); + mockDomainObject.getModel.and.returnValue(testModel); capability = new CostCapability(mockDomainObject); }); diff --git a/platform/features/timeline/test/capabilities/CumulativeGraphSpec.js b/platform/features/timeline/test/capabilities/CumulativeGraphSpec.js index 15c062d61c..22ba91657a 100644 --- a/platform/features/timeline/test/capabilities/CumulativeGraphSpec.js +++ b/platform/features/timeline/test/capabilities/CumulativeGraphSpec.js @@ -37,11 +37,11 @@ define( ['getPointCount', 'getDomainValue', 'getRangeValue'] ); - mockGraph.getPointCount.andReturn(points.length * 2); - mockGraph.getDomainValue.andCallFake(function (i) { + mockGraph.getPointCount.and.returnValue(points.length * 2); + mockGraph.getDomainValue.and.callFake(function (i) { return Math.floor(i / 2) * 100 + 25; }); - mockGraph.getRangeValue.andCallFake(function (i) { + mockGraph.getRangeValue.and.callFake(function (i) { return points[Math.floor(i / 2) + i % 2]; }); diff --git a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js index e2ccd376e2..73dfd9cd40 100644 --- a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js @@ -53,8 +53,8 @@ define( } }; - mockQ.when.andCallFake(asPromise); - mockDomainObject.getModel.andReturn(testModel); + mockQ.when.and.callFake(asPromise); + mockDomainObject.getModel.and.returnValue(testModel); capability = new GraphCapability( mockQ, @@ -82,7 +82,7 @@ define( it("provides one graph per resource type", function () { var mockCallback = jasmine.createSpy('callback'); - mockDomainObject.useCapability.andReturn(asPromise([ + mockDomainObject.useCapability.and.returnValue(asPromise([ { key: "abc", start: 0, end: 15 }, { key: "abc", start: 0, end: 15 }, { key: "def", start: 4, end: 15 }, @@ -103,7 +103,7 @@ define( testModel.capacity = 1000; testModel.startingSOC = 100; testModel.type = "timeline"; - mockDomainObject.useCapability.andReturn(asPromise([ + mockDomainObject.useCapability.and.returnValue(asPromise([ { key: "power", start: 0, end: 15 } ])); capability.invoke().then(mockCallback); diff --git a/platform/features/timeline/test/capabilities/TimelineTimespanCapabilitySpec.js b/platform/features/timeline/test/capabilities/TimelineTimespanCapabilitySpec.js index 1c0acb064d..b8bc198090 100644 --- a/platform/features/timeline/test/capabilities/TimelineTimespanCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/TimelineTimespanCapabilitySpec.js @@ -64,8 +64,8 @@ define( ['getEnd'] ); - mockQ.when.andCallFake(asPromise); - mockQ.all.andCallFake(function (values) { + mockQ.when.and.callFake(asPromise); + mockQ.all.and.callFake(function (values) { var result = []; function addResult(v) { result.push(v); @@ -76,7 +76,7 @@ define( values.forEach(promiseResult); return asPromise(result); }); - mockDomainObject.getModel.andReturn({ + mockDomainObject.getModel.and.returnValue({ start: { timestamp: 42000, epoch: "TEST" @@ -85,17 +85,17 @@ define( timestamp: 12321 } }); - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { if (c === 'composition') { return asPromise([mockChildA, mockChildB]); } }); - mockChildA.hasCapability.andReturn(true); - mockChildB.hasCapability.andReturn(true); - mockChildA.useCapability.andCallFake(function (c) { + mockChildA.hasCapability.and.returnValue(true); + mockChildB.hasCapability.and.returnValue(true); + mockChildA.useCapability.and.callFake(function (c) { return c === 'timespan' && mockTimespanA; }); - mockChildB.useCapability.andCallFake(function (c) { + mockChildB.useCapability.and.callFake(function (c) { return c === 'timespan' && mockTimespanB; }); @@ -129,7 +129,7 @@ define( getEpoch: jasmine.any(Function) }); // Finally, verify that getEnd recurses - mockCallback.mostRecentCall.args[0].getEnd(); + mockCallback.calls.mostRecent().args[0].getEnd(); expect(mockTimespanA.getEnd).toHaveBeenCalled(); expect(mockTimespanB.getEnd).toHaveBeenCalled(); }); diff --git a/platform/features/timeline/test/capabilities/TimelineTimespanSpec.js b/platform/features/timeline/test/capabilities/TimelineTimespanSpec.js index 11accfffef..3d352b9a45 100644 --- a/platform/features/timeline/test/capabilities/TimelineTimespanSpec.js +++ b/platform/features/timeline/test/capabilities/TimelineTimespanSpec.js @@ -36,7 +36,7 @@ define( 'timespan-' + end, ['getEnd'] ); - mockTimespan.getEnd.andReturn(end); + mockTimespan.getEnd.and.returnValue(end); return mockTimespan; } @@ -53,7 +53,7 @@ define( mockMutation = jasmine.createSpyObj("mutation", ["mutate"]); mockTimespans = [44000, 65000, 1100].map(makeMockTimespan); - mockMutation.mutate.andCallFake(function (mutator) { + mockMutation.mutate.and.callFake(function (mutator) { mutator(mutationModel); }); diff --git a/platform/features/timeline/test/capabilities/UtilizationCapabilitySpec.js b/platform/features/timeline/test/capabilities/UtilizationCapabilitySpec.js index 8418d9ebe3..8ae3e3e571 100644 --- a/platform/features/timeline/test/capabilities/UtilizationCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/UtilizationCapabilitySpec.js @@ -108,13 +108,13 @@ define( relationship: mockRelationship }; - mockQ.when.andCallFake(asPromise); - mockQ.all.andCallFake(allPromises); - mockDomainObject.getModel.andReturn(testModel); - mockDomainObject.getCapability.andCallFake(function (c) { + mockQ.when.and.callFake(asPromise); + mockQ.all.and.callFake(allPromises); + mockDomainObject.getModel.and.returnValue(testModel); + mockDomainObject.getCapability.and.callFake(function (c) { return testCapabilities[c]; }); - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return testCapabilities[c] && testCapabilities[c].invoke(); }); @@ -142,7 +142,7 @@ define( }); it("accumulates resources from composition", function () { - mockComposition.invoke.andReturn(asPromise([ + mockComposition.invoke.and.returnValue(asPromise([ fakeDomainObject(['abc', 'def']), fakeDomainObject(['def', 'xyz']), fakeDomainObject(['abc', 'xyz']) @@ -155,7 +155,7 @@ define( }); it("accumulates utilizations from composition", function () { - mockComposition.invoke.andReturn(asPromise([ + mockComposition.invoke.and.returnValue(asPromise([ fakeDomainObject(['abc', 'def'], 10, 100), fakeDomainObject(['def', 'xyz'], 50, 90) ])); @@ -179,16 +179,16 @@ define( 'timespanCapability', ['invoke'] ); - mockComposition.invoke.andReturn(asPromise([])); - mockRelationship.getRelatedObjects.andReturn(asPromise([ + mockComposition.invoke.and.returnValue(asPromise([])); + mockRelationship.getRelatedObjects.and.returnValue(asPromise([ fakeDomainObject([], 0, 0, { abc: 5, xyz: 15 }) ])); testCapabilities.timespan = mockTimespanCapability; - mockTimespanCapability.invoke.andReturn(asPromise(mockTimespan)); - mockTimespan.getStart.andReturn(42); - mockTimespan.getEnd.andReturn(12321); - mockTimespan.getEpoch.andReturn("TEST"); + mockTimespanCapability.invoke.and.returnValue(asPromise(mockTimespan)); + mockTimespan.getStart.and.returnValue(42); + mockTimespan.getEnd.and.returnValue(12321); + mockTimespan.getEpoch.and.returnValue("TEST"); capability.invoke().then(mockCallback); @@ -199,8 +199,8 @@ define( }); it("provides resource keys from related objects", function () { - mockComposition.invoke.andReturn(asPromise([])); - mockRelationship.getRelatedObjects.andReturn(asPromise([ + mockComposition.invoke.and.returnValue(asPromise([])); + mockRelationship.getRelatedObjects.and.returnValue(asPromise([ fakeDomainObject([], 0, 0, { abc: 5, xyz: 15 }) ])); diff --git a/platform/features/timeline/test/chart/Canvas2DChartSpec.js b/platform/features/timeline/test/chart/Canvas2DChartSpec.js index 65cfb79fa2..edaed99025 100644 --- a/platform/features/timeline/test/chart/Canvas2DChartSpec.js +++ b/platform/features/timeline/test/chart/Canvas2DChartSpec.js @@ -45,7 +45,7 @@ define( "fillRect" ] ); - mockCanvas.getContext.andReturn(mock2d); + mockCanvas.getContext.and.returnValue(mock2d); chart = new Canvas2DChart(mockCanvas); }); @@ -60,7 +60,7 @@ define( }); it("does not construct if 2D is unavailable", function () { - mockCanvas.getContext.andReturn(undefined); + mockCanvas.getContext.and.returnValue(undefined); expect(function () { return new Canvas2DChart(mockCanvas); }).toThrow(); @@ -77,7 +77,7 @@ define( testPoints = 2; chart.drawLine(testBuffer, testColor, testPoints); expect(mock2d.beginPath).toHaveBeenCalled(); - expect(mock2d.lineTo.calls.length).toEqual(1); + expect(mock2d.lineTo.calls.count()).toEqual(1); expect(mock2d.stroke).toHaveBeenCalled(); }); diff --git a/platform/features/timeline/test/chart/GLChartSpec.js b/platform/features/timeline/test/chart/GLChartSpec.js index 44ecf1d283..802347863c 100644 --- a/platform/features/timeline/test/chart/GLChartSpec.js +++ b/platform/features/timeline/test/chart/GLChartSpec.js @@ -68,11 +68,11 @@ define( // Echo back names for uniform locations, so we can // test which of these are set for certain operations. - mockGL.getUniformLocation.andCallFake(function (a, name) { + mockGL.getUniformLocation.and.callFake(function (a, name) { return name; }); - mockCanvas.getContext.andReturn(mockGL); + mockCanvas.getContext.and.returnValue(mockGL); glChart = new GLChart(mockCanvas); }); @@ -83,7 +83,7 @@ define( }); it("does not construct if WebGL is unavailable", function () { - mockCanvas.getContext.andReturn(undefined); + mockCanvas.getContext.and.returnValue(undefined); expect(function () { return new GLChart(mockCanvas); }).toThrow(); diff --git a/platform/features/timeline/test/chart/MCTTimelineChartSpec.js b/platform/features/timeline/test/chart/MCTTimelineChartSpec.js index c0f551dcb1..f7d2f1f39a 100644 --- a/platform/features/timeline/test/chart/MCTTimelineChartSpec.js +++ b/platform/features/timeline/test/chart/MCTTimelineChartSpec.js @@ -91,15 +91,15 @@ define( // Echo back names for uniform locations, so we can // test which of these are set for certain operations. - mockGL.getUniformLocation.andCallFake(function (a, name) { + mockGL.getUniformLocation.and.callFake(function (a, name) { return name; }); - mockElement.find.andReturn([mockCanvas]); - mockCanvas.getContext.andCallFake(function (type) { + mockElement.find.and.returnValue([mockCanvas]); + mockCanvas.getContext.and.callFake(function (type) { return { webgl: mockGL, '2d': mockC2d }[type]; }); - mockInterval.andReturn(mockPromise); + mockInterval.and.returnValue(mockPromise); mctChart = new MCTTimelineChart(mockInterval, mockLog); }); @@ -121,15 +121,15 @@ define( it("issues one draw call per line", function () { mctChart.link(mockScope, mockElement); - mockScope.$watchCollection.mostRecentCall.args[1]({ + mockScope.$watchCollection.calls.mostRecent().args[1]({ lines: [{}, {}, {}] }); - expect(mockGL.drawArrays.calls.length).toEqual(3); + expect(mockGL.drawArrays.calls.count()).toEqual(3); }); it("issues one draw call per box", function () { mctChart.link(mockScope, mockElement); - mockScope.$watchCollection.mostRecentCall.args[1]({ + mockScope.$watchCollection.calls.mostRecent().args[1]({ boxes: [ { start: [0, 0], end: [1, 1] }, { start: [0, 0], end: [1, 1] }, @@ -137,12 +137,12 @@ define( { start: [0, 0], end: [1, 1] } ] }); - expect(mockGL.drawArrays.calls.length).toEqual(4); + expect(mockGL.drawArrays.calls.count()).toEqual(4); }); it("does not fail if no draw object is in scope", function () { mctChart.link(mockScope, mockElement); - expect(mockScope.$watchCollection.mostRecentCall.args[1]) + expect(mockScope.$watchCollection.calls.mostRecent().args[1]) .not.toThrow(); }); @@ -164,14 +164,14 @@ define( mockCanvas.offsetWidth = 150; mockCanvas.height = 200; mockCanvas.offsetHeight = 200; - mockInterval.mostRecentCall.args[0](); + mockInterval.calls.mostRecent().args[0](); // Use clear as an indication that drawing has occurred expect(mockGL.clear).toHaveBeenCalled(); }); it("warns if no WebGL context is available", function () { - mockCanvas.getContext.andReturn(undefined); + mockCanvas.getContext.and.returnValue(undefined); mctChart.link(mockScope, mockElement); expect(mockLog.warn).toHaveBeenCalled(); }); @@ -181,7 +181,7 @@ define( expect(mockCanvas.addEventListener) .toHaveBeenCalledWith("webglcontextlost", jasmine.any(Function)); expect(mockCanvas.getContext).not.toHaveBeenCalledWith('2d'); - mockCanvas.addEventListener.mostRecentCall.args[1](); + mockCanvas.addEventListener.calls.mostRecent().args[1](); expect(mockCanvas.getContext).toHaveBeenCalledWith('2d'); }); @@ -205,7 +205,7 @@ define( expect(mockInterval.cancel).not.toHaveBeenCalled(); // Broadcast a $destroy - mockScope.$on.mostRecentCall.args[1](); + mockScope.$on.calls.mostRecent().args[1](); // Should have stopped the interval expect(mockInterval.cancel).toHaveBeenCalledWith(mockPromise); diff --git a/platform/features/timeline/test/controllers/TimelineControllerSpec.js b/platform/features/timeline/test/controllers/TimelineControllerSpec.js index cd13bf3d28..275387f6a7 100644 --- a/platform/features/timeline/test/controllers/TimelineControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineControllerSpec.js @@ -69,7 +69,7 @@ define( } function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -114,23 +114,23 @@ define( mockScope.domainObject = mockDomainObject; mockScope.configuration = testConfiguration; - mockQ.when.andCallFake(asPromise); - mockQ.all.andCallFake(allPromises); - mockA.getId.andReturn('a'); - mockA.getModel.andReturn(testModels.a); - mockB.getId.andReturn('b'); - mockB.getModel.andReturn(testModels.b); - mockA.useCapability.andCallFake(useCapability); - mockB.useCapability.andCallFake(useCapability); - mockA.hasCapability.andReturn(true); - mockB.hasCapability.andReturn(true); - mockA.getCapability.andCallFake(getCapability); - mockB.getCapability.andCallFake(getCapability); - mockSpan.getStart.andReturn(42); - mockSpan.getEnd.andReturn(12321); - mockUtilization.resources.andReturn(['abc', 'xyz']); - mockUtilization.utilization.andReturn(mockPromise); - mockLoader.load.andCallFake(function () { + mockQ.when.and.callFake(asPromise); + mockQ.all.and.callFake(allPromises); + mockA.getId.and.returnValue('a'); + mockA.getModel.and.returnValue(testModels.a); + mockB.getId.and.returnValue('b'); + mockB.getModel.and.returnValue(testModels.b); + mockA.useCapability.and.callFake(useCapability); + mockB.useCapability.and.callFake(useCapability); + mockA.hasCapability.and.returnValue(true); + mockB.hasCapability.and.returnValue(true); + mockA.getCapability.and.callFake(getCapability); + mockB.getCapability.and.callFake(getCapability); + mockSpan.getStart.and.returnValue(42); + mockSpan.getEnd.and.returnValue(12321); + mockUtilization.resources.and.returnValue(['abc', 'xyz']); + mockUtilization.utilization.and.returnValue(mockPromise); + mockLoader.load.and.callFake(function () { return asPromise(subgraph(mockA, { a: mockA, b: mockB @@ -160,7 +160,7 @@ define( var fnWatchCall; // Find the $watch that was given a function - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (typeof call.args[0] === 'function') { // white-box: we know the first call is // the one we're looking for @@ -197,17 +197,17 @@ define( expect(controller.graphs().length).toEqual(0); // Execute the watch function for graph state - tmp = mockScope.$watch.calls[3].args[0](); + tmp = mockScope.$watch.calls.all()[3].args[0](); // Change graph state testConfiguration.graph = { a: true, b: true }; // Verify that this would have triggered a watch - expect(mockScope.$watch.calls[3].args[0]()) + expect(mockScope.$watch.calls.all()[3].args[0]()) .not.toEqual(tmp); // Run the function the watch would have triggered - mockScope.$watch.calls[3].args[1](); + mockScope.$watch.calls.all()[3].args[1](); // Should have some graphs now expect(controller.graphs().length).toEqual(2); diff --git a/platform/features/timeline/test/controllers/TimelineDateTimeControllerSpec.js b/platform/features/timeline/test/controllers/TimelineDateTimeControllerSpec.js index ad076d6407..9a802a85a9 100644 --- a/platform/features/timeline/test/controllers/TimelineDateTimeControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineDateTimeControllerSpec.js @@ -40,9 +40,9 @@ define( // Verify two-way binding support it("updates model on changes to entry fields", function () { // Make sure we're looking at the right watch - expect(mockScope.$watchCollection.calls[0].args[0]) + expect(mockScope.$watchCollection.calls.all()[0].args[0]) .toEqual("datetime"); - mockScope.$watchCollection.calls[0].args[1]({ + mockScope.$watchCollection.calls.all()[0].args[1]({ days: 4, hours: 12, minutes: 30, @@ -55,12 +55,12 @@ define( it("updates form when model changes", function () { // Make sure we're looking at the right watch - expect(mockScope.$watchCollection.calls[1].args[0]) + expect(mockScope.$watchCollection.calls.all()[1].args[0]) .toEqual(jasmine.any(Function)); // ...and that it's really looking at the field in ngModel - expect(mockScope.$watchCollection.calls[1].args[0]()) + expect(mockScope.$watchCollection.calls.all()[1].args[0]()) .toBe(mockScope.ngModel.testField); - mockScope.$watchCollection.calls[1].args[1]({ + mockScope.$watchCollection.calls.all()[1].args[1]({ timestamp: ((((((4 * 24) + 12) * 60) + 30) * 60) + 11) * 1000 }); expect(mockScope.datetime).toEqual({ diff --git a/platform/features/timeline/test/controllers/TimelineGanttControllerSpec.js b/platform/features/timeline/test/controllers/TimelineGanttControllerSpec.js index a39e4009d9..4869e143be 100644 --- a/platform/features/timeline/test/controllers/TimelineGanttControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineGanttControllerSpec.js @@ -57,11 +57,11 @@ define( testScroll = { x: 0, width: 2000 }; mockToPixels = jasmine.createSpy('toPixels'); - mockTimespan.getStart.andReturn(100); - mockTimespan.getDuration.andReturn(50); - mockTimespan.getEnd.andReturn(150); + mockTimespan.getStart.and.returnValue(100); + mockTimespan.getDuration.and.returnValue(50); + mockTimespan.getEnd.and.returnValue(150); - mockToPixels.andCallFake(function (t) { + mockToPixels.and.callFake(function (t) { return t * 10; }); diff --git a/platform/features/timeline/test/controllers/TimelineGraphControllerSpec.js b/platform/features/timeline/test/controllers/TimelineGraphControllerSpec.js index e59832dc0b..b0f868c5db 100644 --- a/platform/features/timeline/test/controllers/TimelineGraphControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineGraphControllerSpec.js @@ -57,7 +57,7 @@ define( mockGraphB = jasmine.createSpyObj('graph-b', ['setBounds']); // Supply new parameters - mockScope.$watchCollection.mostRecentCall.args[1]({ + mockScope.$watchCollection.calls.mostRecent().args[1]({ graphs: [mockGraphA, mockGraphB], origin: 9, duration: 144 @@ -71,8 +71,8 @@ define( it("provides labels for graphs", function () { var mockGraph = jasmine.createSpyObj('graph', ['minimum', 'maximum']); - mockGraph.minimum.andReturn(12.3412121); - mockGraph.maximum.andReturn(88.7555555); + mockGraph.minimum.and.returnValue(12.3412121); + mockGraph.maximum.and.returnValue(88.7555555); mockGraph.key = "def"; expect(controller.label(mockGraph)).toEqual({ diff --git a/platform/features/timeline/test/controllers/TimelineTOIControllerSpec.js b/platform/features/timeline/test/controllers/TimelineTOIControllerSpec.js index d3345ad64b..e9b14db489 100644 --- a/platform/features/timeline/test/controllers/TimelineTOIControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineTOIControllerSpec.js @@ -46,10 +46,10 @@ define([ ]); mockScope.scroll = { x: 10, width: 1000 }; - spyOn(mockmct.time, "on").andCallThrough(); - spyOn(mockmct.time, "off").andCallThrough(); - spyOn(mockTimerService, "on").andCallThrough(); - spyOn(mockTimerService, "off").andCallThrough(); + spyOn(mockmct.time, "on").and.callThrough(); + spyOn(mockmct.time, "off").and.callThrough(); + spyOn(mockTimerService, "on").and.callThrough(); + spyOn(mockTimerService, "off").and.callThrough(); controller = new TimelineTOIController( mockmct, @@ -96,11 +96,11 @@ define([ beforeEach(function () { testNow = 333221; mockScope.zoomController.toPixels - .andCallFake(function (millis) { + .and.callFake(function (millis) { return millis * 2; }); mockTimerService.emit('change', mockTimer); - mockTimerService.now.andReturn(testNow); + mockTimerService.now.and.returnValue(testNow); }); it("reports an x value from the zoomController", function () { @@ -125,7 +125,7 @@ define([ describe("when follow mode is enabled", function () { beforeEach(function () { mockScope.scroll.follow = true; - mockTimerService.now.andReturn(500); + mockTimerService.now.and.returnValue(500); }); it("zooms on bounds events", function () { diff --git a/platform/features/timeline/test/controllers/TimelineTickControllerSpec.js b/platform/features/timeline/test/controllers/TimelineTickControllerSpec.js index c4dfd3679d..fb07c88433 100644 --- a/platform/features/timeline/test/controllers/TimelineTickControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineTickControllerSpec.js @@ -40,7 +40,7 @@ define( beforeEach(function () { mockToMillis = jasmine.createSpy('toMillis'); - mockToMillis.andCallFake(function (v) { + mockToMillis.and.callFake(function (v) { return v * 2 + BILLION; }); controller = new TimelineTickController(); @@ -69,7 +69,7 @@ define( it("does rebuild arrays when zoom changes", function () { var firstValue = controller.labels(800, 300, 100, mockToMillis); - mockToMillis.andCallFake(function (v) { + mockToMillis.and.callFake(function (v) { return BILLION * 2 + v; }); diff --git a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js index 4a067483e9..dc5191f038 100644 --- a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js @@ -95,24 +95,24 @@ define( 'getDuration' ]); - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.useCapability.and.callFake(function (c) { return c === 'timespan' && mockPromise; }); - mockPromise.then.andCallFake(function (callback) { + mockPromise.then.and.callFake(function (callback) { callback(mockTimespan); }); - mockTimespan.getStart.andReturn(testStart); - mockTimespan.getEnd.andReturn(testEnd); - mockTimespan.getDuration.andReturn(testEnd - testStart); + mockTimespan.getStart.and.returnValue(testStart); + mockTimespan.getEnd.and.returnValue(testEnd); + mockTimespan.getDuration.and.returnValue(testEnd - testStart); mockScope.scroll = { x: 0, width: 20000 }; mockScope.domainObject = mockDomainObject; - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { call.args[1](mockScope[call.args[0]]); }); - mockWindow.requestAnimationFrame.calls.forEach(function (call) { + mockWindow.requestAnimationFrame.calls.all().forEach(function (call) { call.args[0](); }); }); diff --git a/platform/features/timeline/test/controllers/drag/TimelineDragHandleFactorySpec.js b/platform/features/timeline/test/controllers/drag/TimelineDragHandleFactorySpec.js index 6b5696ae4a..6c0d0bf50f 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineDragHandleFactorySpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineDragHandleFactorySpec.js @@ -50,9 +50,9 @@ define( ['instanceOf'] ); - mockDomainObject.getId.andReturn('test-id'); - mockDomainObject.getCapability.andReturn(mockType); - mockType.instanceOf.andCallFake(function (t) { + mockDomainObject.getId.and.returnValue('test-id'); + mockDomainObject.getCapability.and.returnValue(mockType); + mockType.instanceOf.and.callFake(function (t) { return t === testType; }); diff --git a/platform/features/timeline/test/controllers/drag/TimelineDragHandlerSpec.js b/platform/features/timeline/test/controllers/drag/TimelineDragHandlerSpec.js index 03bb50504a..5a3a5b9094 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineDragHandlerSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineDragHandlerSpec.js @@ -60,10 +60,10 @@ define( ['getId', 'getModel', 'getCapability', 'useCapability'] ); - mockDomainObj.getId.andReturn(id); - mockDomainObj.getModel.andReturn({ composition: composition }); - mockDomainObj.useCapability.andReturn(asPromise(mockTimespans[id])); - mockDomainObj.getCapability.andCallFake(function (c) { + mockDomainObj.getId.and.returnValue(id); + mockDomainObj.getModel.and.returnValue({ composition: composition }); + mockDomainObj.useCapability.and.returnValue(asPromise(mockTimespans[id])); + mockDomainObj.getCapability.and.callFake(function (c) { return { mutation: mockMutations[id] }[c]; @@ -84,9 +84,9 @@ define( 'mutation-' + id, ['mutate'] ); - mockTimespans[id].getStart.andReturn(index * 1000); - mockTimespans[id].getDuration.andReturn(4000 + index); - mockTimespans[id].getEnd.andReturn(4000 + index + index * 1000); + mockTimespans[id].getStart.and.returnValue(index * 1000); + mockTimespans[id].getDuration.and.returnValue(4000 + index); + mockTimespans[id].getEnd.and.returnValue(4000 + index + index * 1000); }); mockLoader = jasmine.createSpyObj('objectLoader', ['load']); @@ -104,7 +104,7 @@ define( testConfiguration = {}; - mockLoader.load.andReturn(asPromise( + mockLoader.load.and.returnValue(asPromise( subgraph(mockDomainObject, mockDomainObjects) )); @@ -193,7 +193,7 @@ define( it("prevents bulk moves past 0", function () { // Have a start later; new lowest start is b, at 1000 - mockTimespans.a.getStart.andReturn(10000); + mockTimespans.a.getStart.and.returnValue(10000); handler.move('a', -10000); // Verify that move was stopped at 0, for b, even though // move was initiated at a diff --git a/platform/features/timeline/test/controllers/drag/TimelineDragPopulatorSpec.js b/platform/features/timeline/test/controllers/drag/TimelineDragPopulatorSpec.js index a964d40528..fef5871e93 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineDragPopulatorSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineDragPopulatorSpec.js @@ -42,7 +42,7 @@ define( ); mockSwimlane.domainObject = mockDomainObject; - mockObjectLoader.load.andReturn(mockPromise); + mockObjectLoader.load.and.returnValue(mockPromise); populator = new TimelineDragPopulator(mockObjectLoader); }); diff --git a/platform/features/timeline/test/controllers/drag/TimelineEndHandleSpec.js b/platform/features/timeline/test/controllers/drag/TimelineEndHandleSpec.js index f657da7cad..4cc15f08e4 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineEndHandleSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineEndHandleSpec.js @@ -44,19 +44,19 @@ define( ['toMillis', 'toPixels'] ); - mockDragHandler.end.andReturn(12321); + mockDragHandler.end.and.returnValue(12321); // Echo back the value from snapper for most tests - mockSnapHandler.snap.andCallFake(function (ts) { + mockSnapHandler.snap.and.callFake(function (ts) { return ts; }); // Double pixels to get millis, for test purposes - mockZoomController.toMillis.andCallFake(function (px) { + mockZoomController.toMillis.and.callFake(function (px) { return px * 2; }); - mockZoomController.toPixels.andCallFake(function (ms) { + mockZoomController.toPixels.and.callFake(function (ms) { return ms / 2; }); @@ -88,7 +88,7 @@ define( }); it("snaps drags to other end points", function () { - mockSnapHandler.snap.andReturn(42); + mockSnapHandler.snap.and.returnValue(42); handle.begin(); handle.drag(-10, mockZoomController); // Should have used snap-to timestamp diff --git a/platform/features/timeline/test/controllers/drag/TimelineMoveHandleSpec.js b/platform/features/timeline/test/controllers/drag/TimelineMoveHandleSpec.js index e2523e0b58..ea9263c1dd 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineMoveHandleSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineMoveHandleSpec.js @@ -44,21 +44,21 @@ define( ['toMillis', 'toPixels'] ); - mockDragHandler.start.andReturn(12321); - mockDragHandler.duration.andReturn(4200); - mockDragHandler.end.andReturn(12321 + 4200); + mockDragHandler.start.and.returnValue(12321); + mockDragHandler.duration.and.returnValue(4200); + mockDragHandler.end.and.returnValue(12321 + 4200); // Echo back the value from snapper for most tests - mockSnapHandler.snap.andCallFake(function (ts) { + mockSnapHandler.snap.and.callFake(function (ts) { return ts; }); // Double pixels to get millis, for test purposes - mockZoomController.toMillis.andCallFake(function (px) { + mockZoomController.toMillis.and.callFake(function (px) { return px * 2; }); - mockZoomController.toPixels.andCallFake(function (ms) { + mockZoomController.toPixels.and.callFake(function (ms) { return ms / 2; }); @@ -100,8 +100,8 @@ define( ); // Reflect the change from the drag handler - mockDragHandler.start.andReturn(12521); - mockDragHandler.end.andReturn(12521 + 4200); + mockDragHandler.start.and.returnValue(12521); + mockDragHandler.end.and.returnValue(12521 + 4200); // ....followed by a +100 ms change. handle.drag(150, mockZoomController); @@ -112,7 +112,7 @@ define( }); it("snaps drags to other end points", function () { - mockSnapHandler.snap.andCallFake(function (ts) { + mockSnapHandler.snap.and.callFake(function (ts) { return ts + 10; }); handle.begin(); @@ -129,7 +129,7 @@ define( handle.begin(); expect(mockSnapHandler.snap).not.toHaveBeenCalled(); handle.drag(100, mockZoomController); - expect(mockSnapHandler.snap.calls.length).toEqual(2); + expect(mockSnapHandler.snap.calls.count()).toEqual(2); }); it("chooses the closest snap-to location", function () { @@ -139,7 +139,7 @@ define( // regardless of whether it is the start/end (which // will vary based on the initial state of this toggle.) var toggle = false; - mockSnapHandler.snap.andCallFake(function (ts) { + mockSnapHandler.snap.and.callFake(function (ts) { toggle = !toggle; return ts + (toggle ? -5 : 10); }); @@ -151,8 +151,8 @@ define( ); // Reflect the change from the drag handler - mockDragHandler.start.andReturn(12521 - 5); - mockDragHandler.end.andReturn(12521 + 4200 - 5); + mockDragHandler.start.and.returnValue(12521 - 5); + mockDragHandler.end.and.returnValue(12521 + 4200 - 5); toggle = true; // Change going-in state handle.drag(300, mockZoomController); diff --git a/platform/features/timeline/test/controllers/drag/TimelineSnapHandlerSpec.js b/platform/features/timeline/test/controllers/drag/TimelineSnapHandlerSpec.js index 2517c1c907..eaffb86d18 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineSnapHandlerSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineSnapHandlerSpec.js @@ -37,11 +37,11 @@ define( ['start', 'end', 'ids'] ); - mockDragHandler.ids.andReturn(['a', 'b', 'c', 'd']); - mockDragHandler.start.andCallFake(function (id) { + mockDragHandler.ids.and.returnValue(['a', 'b', 'c', 'd']); + mockDragHandler.start.and.callFake(function (id) { return starts[id]; }); - mockDragHandler.end.andCallFake(function (id) { + mockDragHandler.end.and.callFake(function (id) { return ends[id]; }); diff --git a/platform/features/timeline/test/controllers/drag/TimelineStartHandleSpec.js b/platform/features/timeline/test/controllers/drag/TimelineStartHandleSpec.js index 7e659bbe43..7df59b17ce 100644 --- a/platform/features/timeline/test/controllers/drag/TimelineStartHandleSpec.js +++ b/platform/features/timeline/test/controllers/drag/TimelineStartHandleSpec.js @@ -44,19 +44,19 @@ define( ['toMillis', 'toPixels'] ); - mockDragHandler.start.andReturn(12321); + mockDragHandler.start.and.returnValue(12321); // Echo back the value from snapper for most tests - mockSnapHandler.snap.andCallFake(function (ts) { + mockSnapHandler.snap.and.callFake(function (ts) { return ts; }); // Double pixels to get millis, for test purposes - mockZoomController.toMillis.andCallFake(function (px) { + mockZoomController.toMillis.and.callFake(function (px) { return px * 2; }); - mockZoomController.toPixels.andCallFake(function (ms) { + mockZoomController.toPixels.and.callFake(function (ms) { return ms / 2; }); @@ -87,7 +87,7 @@ define( }); it("snaps drags to other end points", function () { - mockSnapHandler.snap.andReturn(42); + mockSnapHandler.snap.and.returnValue(42); handle.begin(); handle.drag(-10, mockZoomController); // Should have used snap-to timestamp diff --git a/platform/features/timeline/test/controllers/graph/TimelineGraphPopulatorSpec.js b/platform/features/timeline/test/controllers/graph/TimelineGraphPopulatorSpec.js index 5843a55b7e..6dfd9407b8 100644 --- a/platform/features/timeline/test/controllers/graph/TimelineGraphPopulatorSpec.js +++ b/platform/features/timeline/test/controllers/graph/TimelineGraphPopulatorSpec.js @@ -64,15 +64,15 @@ define( 'graph-' + k, ['getPointCount', 'getDomainValue', 'getRangeValue'] ); - mockSwimlane.graph.andReturn(true); + mockSwimlane.graph.and.returnValue(true); mockSwimlane.domainObject = jasmine.createSpyObj( 'domainObject-' + k, ['getCapability', 'hasCapability', 'useCapability', 'getId'] ); - mockSwimlane.color.andReturn('#' + k); + mockSwimlane.color.and.returnValue('#' + k); // Provide just enough information about graphs to support // determination of which graphs to show - mockSwimlane.domainObject.useCapability.andCallFake(function () { + mockSwimlane.domainObject.useCapability.and.callFake(function () { var obj = {}; testResources[k].forEach(function (r) { obj[r] = mockGraph; @@ -80,16 +80,16 @@ define( return asPromise(obj); }); mockSwimlane.domainObject.hasCapability - .andReturn(true); + .and.returnValue(true); mockSwimlane.domainObject.getId - .andReturn(k); - mockGraph.getPointCount.andReturn(0); + .and.returnValue(k); + mockGraph.getPointCount.and.returnValue(0); return mockSwimlane; }); - mockQ.when.andCallFake(asPromise); - mockQ.all.andCallFake(allPromises); + mockQ.when.and.callFake(asPromise); + mockQ.all.and.callFake(allPromises); populator = new TimelineGraphPopulator(mockQ); }); @@ -105,7 +105,7 @@ define( }); it("does not include graphs based on swimlane configuration", function () { - mockSwimlanes[2].graph.andReturn(false); + mockSwimlanes[2].graph.and.returnValue(false); populator.populate(mockSwimlanes); // Only two unique swimlanes in the other two expect(populator.get().length).toEqual(2); @@ -140,7 +140,7 @@ define( populator.populate(mockSwimlanes); initialValue = populator.get(); // Change resource graph inclusion... - mockSwimlanes[1].graph.andReturn(false); + mockSwimlanes[1].graph.and.returnValue(false); populator.populate(mockSwimlanes); // Now we should get different graphs expect(populator.get()).not.toBe(initialValue); diff --git a/platform/features/timeline/test/controllers/graph/TimelineGraphSpec.js b/platform/features/timeline/test/controllers/graph/TimelineGraphSpec.js index 54d1ecca9d..4b04d545ae 100644 --- a/platform/features/timeline/test/controllers/graph/TimelineGraphSpec.js +++ b/platform/features/timeline/test/controllers/graph/TimelineGraphSpec.js @@ -59,10 +59,10 @@ define( 'domainObject-' + k, ['getCapability', 'useCapability'] ); - mockDomainObjects[k].useCapability.andReturn(asPromise({ + mockDomainObjects[k].useCapability.and.returnValue(asPromise({ testResource: mockGraph })); - mockGraph.getPointCount.andReturn(i + 2); + mockGraph.getPointCount.and.returnValue(i + 2); mockGraph.testField = k; mockGraph.testIndex = i; @@ -75,7 +75,7 @@ define( ['render', 'decode'] ); - mockRenderer.render.andCallFake(function (utilization) { + mockRenderer.render.and.callFake(function (utilization) { var result = []; while (result.length < (utilization.testIndex + 2) * 2) { result.push(Math.floor(result.length / 2)); @@ -88,7 +88,7 @@ define( return result; }); - mockRenderer.decode.andCallFake(function (color) { + mockRenderer.decode.and.callFake(function (color) { return testColors[color]; }); @@ -114,7 +114,7 @@ define( expect(graph.drawingObject.lines).toEqual([ { color: testColors.a, - buffer: [0, 0, 1, 0], + buffer: [0, 0, 1, -0], points: 2 }, { @@ -138,7 +138,7 @@ define( it("provides a minimum/maximum even with no data", function () { mockGraphs.forEach(function (mockGraph) { - mockGraph.getPointCount.andReturn(0); + mockGraph.getPointCount.and.returnValue(0); }); // Create a graph of these utilizations diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js index 115564ba17..88ff210f03 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js @@ -49,12 +49,12 @@ define( 'action-' + type, ['perform', 'getMetadata'] ); - mockAction.getMetadata.andReturn({ type: type }); + mockAction.getMetadata.and.returnValue({ type: type }); return mockAction; }); - mockDomainObject.getCapability.andReturn(mockActionCapability); - mockActionCapability.getActions.andReturn(mockActions); + mockDomainObject.getCapability.and.returnValue(mockActionCapability); + mockActionCapability.getActions.and.returnValue(mockActions); proxy = new TimelineProxy(mockDomainObject, mockSelection); }); @@ -90,10 +90,10 @@ define( ); // Set up mocks - mockSelection.get.andReturn({ domainObject: mockOtherObject }); - mockOtherObject.getCapability.andReturn(mockOtherAction); - mockOtherAction.getActions.andReturn([mockAction]); - mockAction.getMetadata.andReturn({ type: 'z' }); + mockSelection.get.and.returnValue({ domainObject: mockOtherObject }); + mockOtherObject.getCapability.and.returnValue(mockOtherAction); + mockOtherAction.getActions.and.returnValue([mockAction]); + mockAction.getMetadata.and.returnValue({ type: 'z' }); // Invoke add method; should create with selected object proxy.add('z'); diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDecoratorSpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDecoratorSpec.js index 2d777656ee..575d7228d3 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDecoratorSpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDecoratorSpec.js @@ -56,13 +56,13 @@ define( ); mockPromise = jasmine.createSpyObj('promise', ['then']); - mockSwimlane.domainObject.getCapability.andCallFake(function (c) { + mockSwimlane.domainObject.getCapability.and.callFake(function (c) { return mockCapabilities[c]; }); - mockSwimlane.domainObject.getModel.andReturn(testModel); + mockSwimlane.domainObject.getModel.and.returnValue(testModel); - mockCapabilities.type.instanceOf.andReturn(true); - mockCapabilities.mutation.mutate.andReturn(mockPromise); + mockCapabilities.type.instanceOf.and.returnValue(true); + mockCapabilities.mutation.mutate.and.returnValue(mockPromise); decorator = new TimelineSwimlaneDecorator( mockSwimlane, @@ -109,7 +109,7 @@ define( decorator.modes(['abc', 'xyz']); expect(mockCapabilities.mutation.mutate) .toHaveBeenCalledWith(jasmine.any(Function)); - mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel); + mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel); expect(testModel.relationships.modes).toEqual(['abc', 'xyz']); }); @@ -117,7 +117,7 @@ define( decorator.link("http://www.noaa.gov"); expect(mockCapabilities.mutation.mutate) .toHaveBeenCalledWith(jasmine.any(Function)); - mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel); + mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel); expect(testModel.link).toEqual("http://www.noaa.gov"); }); @@ -133,7 +133,7 @@ define( testModel.relationships = { modes: testModes }; decorator.modes(testModes2); expect(mockCapabilities.mutation.mutate).toHaveBeenCalled(); - mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel); + mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel); expect(testModel.relationships.modes).toBe(testModes2); }); @@ -151,7 +151,7 @@ define( ['perform'] ); - mockChild.getCapability.andCallFake(function (c) { + mockChild.getCapability.and.callFake(function (c) { return c === 'action' ? mockAction : undefined; }); @@ -173,7 +173,7 @@ define( it("allows checking for swimlane selection state", function () { expect(decorator.selected()).toBeFalsy(); - mockSelection.get.andReturn(decorator); + mockSelection.get.and.returnValue(decorator); expect(decorator.selected()).toBeTruthy(); }); diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js index 1ea986ae16..85f367ba03 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js @@ -65,8 +65,8 @@ define( ); mockAction = jasmine.createSpyObj('action', ['perform']); - mockAction.perform.andReturn(mockPromise); - mockPromise.then.andCallFake(function (callback) { + mockAction.perform.and.returnValue(mockPromise); + mockPromise.then.and.callFake(function (callback) { callback(); }); @@ -77,48 +77,48 @@ define( mockActionCapability = jasmine.createSpyObj("action", ["perform", "getActions"]); mockContext = jasmine.createSpyObj('context', ['getParent']); - mockActionCapability.getActions.andReturn([mockAction]); - mockSwimlane.parent.domainObject.getId.andReturn('a'); - mockSwimlane.domainObject.getId.andReturn('b'); - mockSwimlane.children[0].domainObject.getId.andReturn('c'); - mockOtherObject.getId.andReturn('d'); + mockActionCapability.getActions.and.returnValue([mockAction]); + mockSwimlane.parent.domainObject.getId.and.returnValue('a'); + mockSwimlane.domainObject.getId.and.returnValue('b'); + mockSwimlane.children[0].domainObject.getId.and.returnValue('c'); + mockOtherObject.getId.and.returnValue('d'); - mockSwimlane.domainObject.getCapability.andCallFake(function (c) { + mockSwimlane.domainObject.getCapability.and.callFake(function (c) { return { action: mockActionCapability, editor: mockEditorCapability }[c]; }); - mockSwimlane.parent.domainObject.getCapability.andCallFake(function (c) { + mockSwimlane.parent.domainObject.getCapability.and.callFake(function (c) { return { action: mockActionCapability, editor: mockEditorCapability }[c]; }); - mockOtherObject.getCapability.andCallFake(function (c) { + mockOtherObject.getCapability.and.callFake(function (c) { return { action: mockActionCapability, context: mockContext, editor: mockEditorCapability }[c]; }); - mockContext.getParent.andReturn(mockOtherObject); + mockContext.getParent.and.returnValue(mockOtherObject); - mockSwimlane.domainObject.hasCapability.andReturn(true); + mockSwimlane.domainObject.hasCapability.and.returnValue(true); handler = new TimelineSwimlaneDropHandler(mockSwimlane); }); it("disallows drop outside of edit mode", function () { - mockEditorCapability.inEditContext.andReturn(true); + mockEditorCapability.inEditContext.and.returnValue(true); // Verify precondition expect(handler.allowDropIn('d', mockSwimlane.domainObject)) .toBeTruthy(); expect(handler.allowDropAfter('d', mockSwimlane.domainObject)) .toBeTruthy(); // Act as if we're not in edit mode - mockEditorCapability.inEditContext.andReturn(false); + mockEditorCapability.inEditContext.and.returnValue(false); // Now, they should be disallowed expect(handler.allowDropIn('d', mockSwimlane.domainObject)) .toBeFalsy(); @@ -149,48 +149,48 @@ define( it("inserts into when highlighted", function () { var testModel = { composition: ['c'] }; - mockSwimlane.highlight.andReturn(true); + mockSwimlane.highlight.and.returnValue(true); handler.drop('d', mockOtherObject); // Should have mutated expect(mockSwimlane.domainObject.useCapability) .toHaveBeenCalledWith("mutation", jasmine.any(Function)); // Run the mutator - mockSwimlane.domainObject.useCapability.mostRecentCall + mockSwimlane.domainObject.useCapability.calls.mostRecent() .args[1](testModel); expect(testModel.composition).toEqual(['c', 'd']); }); it("inserts after as a peer when highlighted at the bottom", function () { var testModel = { composition: ['x', 'b', 'y'] }; - mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.highlightBottom.and.returnValue(true); mockSwimlane.expanded = false; handler.drop('d', mockOtherObject); // Should have mutated expect(mockSwimlane.parent.domainObject.useCapability) .toHaveBeenCalledWith("mutation", jasmine.any(Function)); // Run the mutator - mockSwimlane.parent.domainObject.useCapability.mostRecentCall + mockSwimlane.parent.domainObject.useCapability.calls.mostRecent() .args[1](testModel); expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']); }); it("inserts into when highlighted at the bottom and expanded", function () { var testModel = { composition: ['c'] }; - mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.highlightBottom.and.returnValue(true); mockSwimlane.expanded = true; handler.drop('d', mockOtherObject); // Should have mutated expect(mockSwimlane.domainObject.useCapability) .toHaveBeenCalledWith("mutation", jasmine.any(Function)); // Run the mutator - mockSwimlane.domainObject.useCapability.mostRecentCall + mockSwimlane.domainObject.useCapability.calls.mostRecent() .args[1](testModel); expect(testModel.composition).toEqual(['d', 'c']); }); it("inserts after as a peer when highlighted at the bottom and childless", function () { var testModel = { composition: ['x', 'b', 'y'] }; - mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.highlightBottom.and.returnValue(true); mockSwimlane.expanded = true; mockSwimlane.children = []; handler.drop('d', mockOtherObject); @@ -198,7 +198,7 @@ define( expect(mockSwimlane.parent.domainObject.useCapability) .toHaveBeenCalledWith("mutation", jasmine.any(Function)); // Run the mutator - mockSwimlane.parent.domainObject.useCapability.mostRecentCall + mockSwimlane.parent.domainObject.useCapability.calls.mostRecent() .args[1](testModel); expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']); }); @@ -206,31 +206,28 @@ define( it("allows reordering within a parent", function () { var testModel = { composition: ['x', 'b', 'y', 'd'] }; - mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.highlightBottom.and.returnValue(true); mockSwimlane.expanded = true; mockSwimlane.children = []; - mockContext.getParent - .andReturn(mockSwimlane.parent.domainObject); - handler.drop('d', mockOtherObject); + mockContext.getParent.and.returnValue(mockSwimlane.parent.domainObject); - waitsFor(function () { - return mockSwimlane.parent.domainObject.useCapability - .calls.length > 0; - }); - - runs(function () { - mockSwimlane.parent.domainObject.useCapability.mostRecentCall - .args[1](testModel); + return new Promise(function (resolve, reject) { + mockSwimlane.parent.domainObject.useCapability.and.callFake(function (name, callback) { + resolve(callback); + }); + handler.drop('d', mockOtherObject); + }).then(function (callback) { + callback(testModel); expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']); }); }); it("does not invoke an action when reordering", function () { - mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.highlightBottom.and.returnValue(true); mockSwimlane.expanded = true; mockSwimlane.children = []; mockContext.getParent - .andReturn(mockSwimlane.parent.domainObject); + .and.returnValue(mockSwimlane.parent.domainObject); handler.drop('d', mockOtherObject); expect(mockAction.perform).not.toHaveBeenCalled(); }); diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlanePopulatorSpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlanePopulatorSpec.js index 758be080c6..a68a9e1383 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlanePopulatorSpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlanePopulatorSpec.js @@ -47,9 +47,9 @@ define( ['getId', 'getModel', 'getCapability', 'useCapability'] ); - mockDomainObj.getId.andReturn(id); - mockDomainObj.getModel.andReturn({ composition: composition }); - mockDomainObj.useCapability.andReturn(asPromise(false)); + mockDomainObj.getId.and.returnValue(id); + mockDomainObj.getModel.and.returnValue({ composition: composition }); + mockDomainObj.useCapability.and.returnValue(asPromise(false)); return mockDomainObj; } @@ -84,7 +84,7 @@ define( testConfiguration = {}; - mockLoader.load.andReturn(asPromise(subgraph( + mockLoader.load.and.returnValue(asPromise(subgraph( mockDomainObject, mockDomainObjects ))); @@ -129,7 +129,7 @@ define( populator.populate(mockDomainObject); // Act as if something is already selected - mockSelection.get.andReturn(populator.get()[1]); + mockSelection.get.and.returnValue(populator.get()[1]); // Verify precondition expect(mockSelection.select).not.toHaveBeenCalled(); @@ -139,7 +139,7 @@ define( // Selection should have been preserved expect(mockSelection.select).toHaveBeenCalled(); - expect(mockSelection.select.mostRecentCall.args[0].domainObject) + expect(mockSelection.select.calls.mostRecent().args[0].domainObject) .toEqual(mockDomainObjects.b); }); diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneSpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneSpec.js index 66ddf8d0fe..82c2dcd210 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneSpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneSpec.js @@ -64,12 +64,12 @@ define( ); mockActionCapability = jasmine.createSpyObj('action', ['perform']); - mockParentObject.getId.andReturn('test-parent'); - mockParentObject.getCapability.andReturn(mockActionCapability); - mockParentObject.useCapability.andReturn(asPromise(mockParentTimespan)); - mockParentObject.getModel.andReturn({ name: "Test Parent" }); - mockChildObject.getModel.andReturn({ name: "Test Child" }); - mockChildObject.useCapability.andReturn(asPromise(mockChildTimespan)); + mockParentObject.getId.and.returnValue('test-parent'); + mockParentObject.getCapability.and.returnValue(mockActionCapability); + mockParentObject.useCapability.and.returnValue(asPromise(mockParentTimespan)); + mockParentObject.getModel.and.returnValue({ name: "Test Parent" }); + mockChildObject.getModel.and.returnValue({ name: "Test Child" }); + mockChildObject.useCapability.and.returnValue(asPromise(mockChildTimespan)); testConfiguration = { graph: {} }; @@ -149,7 +149,7 @@ define( }); it("gets colors from the provided assigner", function () { - mockAssigner.get.andReturn("#ABCABC"); + mockAssigner.get.and.returnValue("#ABCABC"); expect(parent.color()).toEqual("#ABCABC"); // Verify that id was passed, and no other interactions expect(mockAssigner.get).toHaveBeenCalledWith('test-parent'); @@ -194,28 +194,28 @@ define( }); it("detects start/end violations", function () { - mockParentTimespan.getStart.andReturn(42); - mockParentTimespan.getEnd.andReturn(12321); + mockParentTimespan.getStart.and.returnValue(42); + mockParentTimespan.getEnd.and.returnValue(12321); // First, start with a valid timespan - mockChildTimespan.getStart.andReturn(84); - mockChildTimespan.getEnd.andReturn(100); + mockChildTimespan.getStart.and.returnValue(84); + mockChildTimespan.getEnd.and.returnValue(100); expect(child.exceeded()).toBeFalsy(); // Start time violation - mockChildTimespan.getStart.andReturn(21); + mockChildTimespan.getStart.and.returnValue(21); expect(child.exceeded()).toBeTruthy(); // Now both in violation - mockChildTimespan.getEnd.andReturn(20000); + mockChildTimespan.getEnd.and.returnValue(20000); expect(child.exceeded()).toBeTruthy(); // And just the end - mockChildTimespan.getStart.andReturn(100); + mockChildTimespan.getStart.and.returnValue(100); expect(child.exceeded()).toBeTruthy(); // Now back to everything's-just-fine - mockChildTimespan.getEnd.andReturn(10000); + mockChildTimespan.getEnd.and.returnValue(10000); expect(child.exceeded()).toBeFalsy(); }); }); diff --git a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js index 334c630027..3c45a52d48 100644 --- a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js +++ b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js @@ -55,18 +55,18 @@ define( stopPropagation: jasmine.createSpy() }; - testEvent.dataTransfer.getData.andReturn('abc'); - mockDndService.getData.andCallFake(function (key) { + testEvent.dataTransfer.getData.and.returnValue('abc'); + mockDndService.getData.and.callFake(function (key) { return key === SwimlaneDragConstants.TIMELINE_SWIMLANE_DRAG_TYPE ? mockSwimlane : undefined; }); - mockSwimlane.graph.andReturn(false); + mockSwimlane.graph.and.returnValue(false); directive = new MCTResourceGraphDrop(mockDndService); directive.link(mockScope, mockElement, testAttrs); - mockElement.on.calls.forEach(function (call) { + mockElement.on.calls.all().forEach(function (call) { handlers[call.args[0]] = call.args[1]; }); }); @@ -78,7 +78,7 @@ define( [false, true].forEach(function (graphing) { describe("when swimlane graph is " + (graphing ? "" : "not ") + "enabled", function () { beforeEach(function () { - mockSwimlane.graph.andReturn(graphing); + mockSwimlane.graph.and.returnValue(graphing); }); diff --git a/platform/features/timeline/test/directives/MCTSwimlaneDragSpec.js b/platform/features/timeline/test/directives/MCTSwimlaneDragSpec.js index 03798a5eaf..96f8cf5143 100644 --- a/platform/features/timeline/test/directives/MCTSwimlaneDragSpec.js +++ b/platform/features/timeline/test/directives/MCTSwimlaneDragSpec.js @@ -48,7 +48,7 @@ define( testAttrs = { mctSwimlaneDrag: "someTestExpr" }; // Simulate evaluation of expressions in scope - mockScope.$eval.andCallFake(function (expr) { + mockScope.$eval.and.callFake(function (expr) { return scopeExprs[expr]; }); @@ -58,7 +58,7 @@ define( // for testing. directive.link(mockScope, mockElement, testAttrs); - mockElement.on.calls.forEach(function (call) { + mockElement.on.calls.all().forEach(function (call) { handlers[call.args[0]] = call.args[1]; }); diff --git a/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js b/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js index 6297843b58..4ed612b13e 100644 --- a/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js +++ b/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js @@ -64,20 +64,20 @@ define( ["getBoundingClientRect"] ); mockElement[0].offsetHeight = TEST_HEIGHT; - mockElement[0].getBoundingClientRect.andReturn({ top: TEST_TOP }); + mockElement[0].getBoundingClientRect.and.returnValue({ top: TEST_TOP }); // Simulate evaluation of expressions in scope scopeExprs.mockSwimlane = mockSwimlane; - mockScope.$eval.andCallFake(function (expr) { + mockScope.$eval.and.callFake(function (expr) { return scopeExprs[expr]; }); - mockSwimlane.allowDropIn.andReturn(true); - mockSwimlane.allowDropAfter.andReturn(true); + mockSwimlane.allowDropIn.and.returnValue(true); + mockSwimlane.allowDropAfter.and.returnValue(true); // Simulate getter-setter behavior - mockSwimlane.highlight.andCallFake(getterSetter(false)); - mockSwimlane.highlightBottom.andCallFake(getterSetter(false)); + mockSwimlane.highlight.and.callFake(getterSetter(false)); + mockSwimlane.highlightBottom.and.callFake(getterSetter(false)); @@ -88,8 +88,8 @@ define( stopPropagation: jasmine.createSpy() }; - testEvent.dataTransfer.getData.andReturn('abc'); - mockDndService.getData.andReturn({ domainObject: 'someDomainObject' }); + testEvent.dataTransfer.getData.and.returnValue('abc'); + mockDndService.getData.and.returnValue({ domainObject: 'someDomainObject' }); directive = new MCTSwimlaneDrop(mockDndService); @@ -97,7 +97,7 @@ define( // for testing. directive.link(mockScope, mockElement, testAttrs); - mockElement.on.calls.forEach(function (call) { + mockElement.on.calls.all().forEach(function (call) { handlers[call.args[0]] = call.args[1]; }); @@ -133,7 +133,7 @@ define( // Near the top testEvent.pageY = TEST_TOP + TEST_HEIGHT / 10; - mockSwimlane.allowDropIn.andReturn(false); + mockSwimlane.allowDropIn.and.returnValue(false); handlers.dragover(testEvent); @@ -145,7 +145,7 @@ define( // Near the top testEvent.pageY = TEST_TOP + TEST_HEIGHT - TEST_HEIGHT / 10; - mockSwimlane.allowDropAfter.andReturn(false); + mockSwimlane.allowDropAfter.and.returnValue(false); handlers.dragover(testEvent); @@ -165,7 +165,7 @@ define( }); it("clears highlights when drag leaves", function () { - mockSwimlane.highlight.andReturn(true); + mockSwimlane.highlight.and.returnValue(true); handlers.dragleave(); expect(mockSwimlane.highlight).toHaveBeenCalledWith(false); expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false); diff --git a/platform/features/timeline/test/services/ObjectLoaderSpec.js b/platform/features/timeline/test/services/ObjectLoaderSpec.js index b77cd307c5..9403dbe6c5 100644 --- a/platform/features/timeline/test/services/ObjectLoaderSpec.js +++ b/platform/features/timeline/test/services/ObjectLoaderSpec.js @@ -57,13 +57,13 @@ define( ['useCapability', 'hasCapability', 'getId'] ); - mockDomainObject.getId.andReturn(id); - mockDomainObject.useCapability.andCallFake(function (c) { + mockDomainObject.getId.and.returnValue(id); + mockDomainObject.useCapability.and.callFake(function (c) { return c === 'composition' ? asPromise(children.map(lookupObject)) : undefined; }); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return (capabilities.indexOf(c) !== -1) || (c === 'composition'); }); mockDomainObjects[id] = mockDomainObject; @@ -79,8 +79,8 @@ define( // Provide subset of q's actual behavior which we // expect object loader to really need - mockQ.when.andCallFake(asPromise); - mockQ.all.andCallFake(function (values) { + mockQ.when.and.callFake(asPromise); + mockQ.all.and.callFake(function (values) { var result = []; function addResult(v) { result.push(v); diff --git a/platform/forms/test/FileInputServiceSpec.js b/platform/forms/test/FileInputServiceSpec.js index 034fc0b772..4213e4cdf9 100644 --- a/platform/forms/test/FileInputServiceSpec.js +++ b/platform/forms/test/FileInputServiceSpec.js @@ -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 ); diff --git a/platform/forms/test/MCTControlSpec.js b/platform/forms/test/MCTControlSpec.js index 277466f2a4..ea7802ba3d 100644 --- a/platform/forms/test/MCTControlSpec.js +++ b/platform/forms/test/MCTControlSpec.js @@ -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 diff --git a/platform/forms/test/MCTFileInputSpec.js b/platform/forms/test/MCTFileInputSpec.js index 7469b67bdd..112ed3846b 100644 --- a/platform/forms/test/MCTFileInputSpec.js +++ b/platform/forms/test/MCTFileInputSpec.js @@ -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] ); }); diff --git a/platform/forms/test/MCTFormSpec.js b/platform/forms/test/MCTFormSpec.js index 2a93f3e9d8..5d91d9b40a 100644 --- a/platform/forms/test/MCTFormSpec.js +++ b/platform/forms/test/MCTFormSpec.js @@ -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); }); diff --git a/platform/forms/test/controllers/DateTimeControllerSpec.js b/platform/forms/test/controllers/DateTimeControllerSpec.js index 55595cb496..015d3911a9 100644 --- a/platform/forms/test/controllers/DateTimeControllerSpec.js +++ b/platform/forms/test/controllers/DateTimeControllerSpec.js @@ -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); } diff --git a/platform/forms/test/controllers/DialogButtonControllerSpec.js b/platform/forms/test/controllers/DialogButtonControllerSpec.js index 29033e6b2e..db30247a50 100644 --- a/platform/forms/test/controllers/DialogButtonControllerSpec.js +++ b/platform/forms/test/controllers/DialogButtonControllerSpec.js @@ -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"); }); diff --git a/platform/forms/test/controllers/FormControllerSpec.js b/platform/forms/test/controllers/FormControllerSpec.js index b09cac0fcd..ac6368d576 100644 --- a/platform/forms/test/controllers/FormControllerSpec.js +++ b/platform/forms/test/controllers/FormControllerSpec.js @@ -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); }); diff --git a/platform/framework/test/FrameworkInitializerSpec.js b/platform/framework/test/FrameworkInitializerSpec.js index 897cb4d2f9..c79e2ffa23 100644 --- a/platform/framework/test/FrameworkInitializerSpec.js +++ b/platform/framework/test/FrameworkInitializerSpec.js @@ -48,21 +48,7 @@ define( // Really just delegates work, can only verify the // order of calls. it("calls injected stages in order", function () { - var result; - - initializer.runApplication([]).then(function (v) { - result = v; - }); - - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { + return initializer.runApplication([]).then(function (result) { expect(result).toEqual( ["loader", "resolver", "registrar", "bootstrapper"] ); diff --git a/platform/framework/test/LogLevelSpec.js b/platform/framework/test/LogLevelSpec.js index 7b9d2f5ad6..32dc9ba703 100644 --- a/platform/framework/test/LogLevelSpec.js +++ b/platform/framework/test/LogLevelSpec.js @@ -62,11 +62,11 @@ define( mockDelegate = jasmine.createSpyObj('$delegate', LOG_METHODS); LOG_METHODS.forEach(function (m) { - mockLog[m].andCallFake(mockMethods[m]); - mockDelegate[m].andCallFake(mockMethods[m]); + mockLog[m].and.callFake(mockMethods[m]); + mockDelegate[m].and.callFake(mockMethods[m]); }); - mockApp.decorator.andCallFake(function (key, decoration) { + mockApp.decorator.and.callFake(function (key, decoration) { // We only expect $log to be decorated if (key === '$log' && decoration[0] === '$delegate') { decoration[1](mockDelegate); diff --git a/platform/framework/test/load/BundleLoaderSpec.js b/platform/framework/test/load/BundleLoaderSpec.js index 51c5f4566e..76d002da52 100644 --- a/platform/framework/test/load/BundleLoaderSpec.js +++ b/platform/framework/test/load/BundleLoaderSpec.js @@ -29,19 +29,11 @@ define( describe("The bundle loader", function () { var loader, - mockCallback, mockHttp, mockLog, mockRegistry, testBundles; - // Used to wait for then-chain resolution; - // native promises may not resolve synchronously, - // even when values are immediately available. - function mockCallbackResolved() { - return mockCallback.calls.length > 0; - } - beforeEach(function () { testBundles = { "bundles.json": ["bundle/a", "bundle/b"], @@ -49,54 +41,45 @@ define( "bundle/b/bundle.json": {"someValue": 7} }; - mockCallback = jasmine.createSpy("callback"); mockHttp = jasmine.createSpyObj("$http", ["get"]); mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]); mockRegistry = jasmine.createSpyObj( 'legacyRegistry', ['list', 'contains', 'get'] ); - mockRegistry.list.andReturn([]); - mockRegistry.contains.andReturn(false); + mockRegistry.list.and.returnValue([]); + mockRegistry.contains.and.returnValue(false); loader = new BundleLoader(mockHttp, mockLog, mockRegistry); }); it("accepts a JSON file name and loads all bundles", function () { // Set up; return named bundles - mockHttp.get.andReturn(Promise.resolve({ data: [] })); + mockHttp.get.and.returnValue(Promise.resolve({ data: [] })); // Call load bundles - loader.loadBundles("test-filename.json").then(mockCallback); - - waitsFor(mockCallbackResolved, "then-chain resolution", 100); - - runs(function () { + return loader.loadBundles("test-filename.json").then(function (bundles) { // Should have loaded the file via $http expect(mockHttp.get).toHaveBeenCalledWith("test-filename.json"); // Should have gotten an empty bundle list - expect(mockCallback).toHaveBeenCalledWith([]); + expect(bundles).toEqual([]); }); }); it("accepts a list of bundle paths", function () { // Set up; return named bundles - mockHttp.get.andCallFake(function (name) { + mockHttp.get.and.callFake(function (name) { return Promise.resolve({data: testBundles[name]}); }); // Call load bundles - loader.loadBundles(["bundle/a", "bundle/b"]).then(mockCallback); - - waitsFor(mockCallbackResolved, "then-chain resolution", 100); - - runs(function () { + return loader.loadBundles(["bundle/a", "bundle/b"]).then(function (bundles) { // Should have gotten back two bundles - expect(mockCallback.mostRecentCall.args[0].length).toEqual(2); + expect(bundles.length).toEqual(2); // They should have the values we expect; don't care about order, // some map/reduce the summation. - expect(mockCallback.mostRecentCall.args[0].map(function (call) { + expect(bundles.map(function (call) { return call.getDefinition().someValue; }).reduce(function (a, b) { return a + b; @@ -106,16 +89,12 @@ define( it("warns about, then ignores, missing bundle declarations", function () { // File-not-found - mockHttp.get.andReturn(Promise.reject(new Error("test error"))); + mockHttp.get.and.returnValue(Promise.reject(new Error("test error"))); // Try and load - loader.loadBundles(["some/bundle"]).then(mockCallback); - - waitsFor(mockCallbackResolved, "then-chain resolution", 100); - - runs(function () { - // Should have gotten zero bundle - expect(mockCallback.mostRecentCall.args[0].length).toEqual(0); + return loader.loadBundles(["some/bundle"]).then(function (bundles) { + // Should have gotten zero bundles + expect(bundles.length).toEqual(0); // They should have the values we expect; don't care about order, // some map/reduce the summation. @@ -126,16 +105,12 @@ define( it("warns about, then ignores, malformed bundle declarations", function () { // File-not-found - mockHttp.get.andReturn(Promise.resolve(["I am not a valid bundle."])); + mockHttp.get.and.returnValue(Promise.resolve(["I am not a valid bundle."])); // Try and load - loader.loadBundles(["some/bundle"]).then(mockCallback); - - waitsFor(mockCallbackResolved, "then-chain resolution", 100); - - runs(function () { + return loader.loadBundles(["some/bundle"]).then(function (bundles) { // Should have gotten zero bundle - expect(mockCallback.mostRecentCall.args[0].length).toEqual(0); + expect(bundles.length).toEqual(0); // They should have the values we expect; don't care about order, // some map/reduce the summation. diff --git a/platform/framework/test/register/CustomRegistrarsSpec.js b/platform/framework/test/register/CustomRegistrarsSpec.js index 85b038bea5..d996dade2b 100644 --- a/platform/framework/test/register/CustomRegistrarsSpec.js +++ b/platform/framework/test/register/CustomRegistrarsSpec.js @@ -64,70 +64,70 @@ define( it("invokes built-in functions on the app", function () { // Verify preconditions, invoke, expect to have been called - expect(mockApp.directive.calls.length).toEqual(0); + expect(mockApp.directive.calls.count()).toEqual(0); customRegistrars.directives([{ key: "a" }, { key: "b" }, { key: "c" }]); - expect(mockApp.directive.calls.length).toEqual(3); + expect(mockApp.directive.calls.count()).toEqual(3); - expect(mockApp.controller.calls.length).toEqual(0); + expect(mockApp.controller.calls.count()).toEqual(0); customRegistrars.controllers([{ key: "a" }, { key: "b" }, { key: "c" }]); - expect(mockApp.controller.calls.length).toEqual(3); + expect(mockApp.controller.calls.count()).toEqual(3); - expect(mockApp.service.calls.length).toEqual(0); + expect(mockApp.service.calls.count()).toEqual(0); customRegistrars.services([{ key: "a" }, { key: "b" }, { key: "c" }]); - expect(mockApp.service.calls.length).toEqual(3); + expect(mockApp.service.calls.count()).toEqual(3); - expect(mockApp.constant.calls.length).toEqual(0); + expect(mockApp.constant.calls.count()).toEqual(0); customRegistrars.constants([{ key: "a", value: "b" }, { key: "b", value: "c" }, { key: "c", value: "d" }]); - expect(mockApp.constant.calls.length).toEqual(3); + expect(mockApp.constant.calls.count()).toEqual(3); - expect(mockApp.run.calls.length).toEqual(0); + expect(mockApp.run.calls.count()).toEqual(0); customRegistrars.runs([jasmine.createSpy("a"), jasmine.createSpy("a"), jasmine.createSpy("a")]); - expect(mockApp.run.calls.length).toEqual(3); + expect(mockApp.run.calls.count()).toEqual(3); }); it("warns when keys are not defined, then skips", function () { // Verify preconditions, invoke, expect to have been called - expect(mockApp.directive.calls.length).toEqual(0); + expect(mockApp.directive.calls.count()).toEqual(0); customRegistrars.directives([{ key: "a" }, { }, { key: "c" }]); - expect(mockApp.directive.calls.length).toEqual(2); - expect(mockLog.warn.calls.length).toEqual(1); + expect(mockApp.directive.calls.count()).toEqual(2); + expect(mockLog.warn.calls.count()).toEqual(1); - expect(mockApp.controller.calls.length).toEqual(0); + expect(mockApp.controller.calls.count()).toEqual(0); customRegistrars.controllers([{ }, { }, { key: "c" }]); - expect(mockApp.controller.calls.length).toEqual(1); - expect(mockLog.warn.calls.length).toEqual(3); + expect(mockApp.controller.calls.count()).toEqual(1); + expect(mockLog.warn.calls.count()).toEqual(3); - expect(mockApp.service.calls.length).toEqual(0); + expect(mockApp.service.calls.count()).toEqual(0); customRegistrars.services([{ }, { }, { }]); - expect(mockApp.service.calls.length).toEqual(0); - expect(mockLog.warn.calls.length).toEqual(6); + expect(mockApp.service.calls.count()).toEqual(0); + expect(mockLog.warn.calls.count()).toEqual(6); - expect(mockApp.constant.calls.length).toEqual(0); + expect(mockApp.constant.calls.count()).toEqual(0); customRegistrars.constants([{ }, { }, { }]); - expect(mockApp.constant.calls.length).toEqual(0); - expect(mockLog.warn.calls.length).toEqual(9); + expect(mockApp.constant.calls.count()).toEqual(0); + expect(mockLog.warn.calls.count()).toEqual(9); // Notably, keys are not needed for run calls }); it("does not re-register duplicate keys", function () { // Verify preconditions, invoke, expect to have been called - expect(mockApp.directive.calls.length).toEqual(0); + expect(mockApp.directive.calls.count()).toEqual(0); customRegistrars.directives([{ key: "a" }, { key: "a" }]); - expect(mockApp.directive.calls.length).toEqual(1); + expect(mockApp.directive.calls.count()).toEqual(1); - expect(mockApp.controller.calls.length).toEqual(0); + expect(mockApp.controller.calls.count()).toEqual(0); customRegistrars.controllers([{ key: "c" }, { key: "c" }, { key: "c" }]); - expect(mockApp.controller.calls.length).toEqual(1); + expect(mockApp.controller.calls.count()).toEqual(1); - expect(mockApp.service.calls.length).toEqual(0); + expect(mockApp.service.calls.count()).toEqual(0); customRegistrars.services([{ key: "b" }, { key: "b" }]); - expect(mockApp.service.calls.length).toEqual(1); + expect(mockApp.service.calls.count()).toEqual(1); // None of this should have warned, this is all // nominal behavior - expect(mockLog.warn.calls.length).toEqual(0); + expect(mockLog.warn.calls.count()).toEqual(0); }); it("allows routes to be registered", function () { @@ -151,20 +151,20 @@ define( customRegistrars.routes(routes); // Give it the route provider based on its config call - mockApp.config.calls.forEach(function (call) { + mockApp.config.calls.all().forEach(function (call) { // Invoke the provided callback call.args[0][1](mockRouteProvider); }); // The "when" clause should have been mapped to the when method... expect(mockRouteProvider.when).toHaveBeenCalled(); - expect(mockRouteProvider.when.mostRecentCall.args[0]).toEqual("foo"); - expect(mockRouteProvider.when.mostRecentCall.args[1].templateUrl) + expect(mockRouteProvider.when.calls.mostRecent().args[0]).toEqual("foo"); + expect(mockRouteProvider.when.calls.mostRecent().args[1].templateUrl) .toEqual("test/bundle/res/templates/test.html"); // ...while the other should have been treated as a default route expect(mockRouteProvider.otherwise).toHaveBeenCalled(); - expect(mockRouteProvider.otherwise.mostRecentCall.args[0].templateUrl) + expect(mockRouteProvider.otherwise.calls.mostRecent().args[0].templateUrl) .toEqual("test/bundle/res/templates/default.html"); }); diff --git a/platform/framework/test/register/ExtensionRegistrarSpec.js b/platform/framework/test/register/ExtensionRegistrarSpec.js index db6c9d4b1a..4ce49ca328 100644 --- a/platform/framework/test/register/ExtensionRegistrarSpec.js +++ b/platform/framework/test/register/ExtensionRegistrarSpec.js @@ -40,7 +40,7 @@ define( mockSorter = jasmine.createSpyObj("sorter", ["sort"]); customRegistrars = {}; - mockSorter.sort.andCallFake(function (v) { + mockSorter.sort.and.callFake(function (v) { return v; }); @@ -59,7 +59,7 @@ define( it("registers extensions with square brackets, as arrays", function () { var callbacks = {}; - mockApp.factory.andCallFake(function (name, value) { + mockApp.factory.and.callFake(function (name, value) { callbacks[name] = value[value.length - 1]; }); registrar.registerExtensions({ things: [{}] }); @@ -78,7 +78,7 @@ define( it("registers empty extension categories when they are needed", function () { var lengths = {}; - mockApp.factory.andCallFake(function (name, value) { + mockApp.factory.and.callFake(function (name, value) { lengths[name] = value.length; }); // Nobody has registered tests[], but it looks like an extension dependency, @@ -100,7 +100,7 @@ define( var a = { a: 'a' }, b = { b: 'b' }, c = { c: 'c' }; // Fake sorting; just reverse the array - mockSorter.sort.andCallFake(function (v) { + mockSorter.sort.and.callFake(function (v) { return v.reverse(); }); @@ -109,7 +109,7 @@ define( // Verify registration interactions occurred in reverse-order [c, b, a].forEach(function (extension, index) { - expect(mockApp.factory.calls[index].args[1][0]()) + expect(mockApp.factory.calls.all()[index].args[1][0]()) .toEqual(extension); }); }); diff --git a/platform/framework/test/register/ExtensionSorterSpec.js b/platform/framework/test/register/ExtensionSorterSpec.js index e21925f68c..5546c63364 100644 --- a/platform/framework/test/register/ExtensionSorterSpec.js +++ b/platform/framework/test/register/ExtensionSorterSpec.js @@ -61,7 +61,7 @@ define( ); // Should have been warned exactly twice (for d & e) - expect(mockLog.warn.calls.length).toEqual(2); + expect(mockLog.warn.calls.count()).toEqual(2); }); }); diff --git a/platform/framework/test/register/ServiceCompositorSpec.js b/platform/framework/test/register/ServiceCompositorSpec.js index 39cb8e2672..3a34a54569 100644 --- a/platform/framework/test/register/ServiceCompositorSpec.js +++ b/platform/framework/test/register/ServiceCompositorSpec.js @@ -40,7 +40,7 @@ define( mockApp = jasmine.createSpyObj("app", ["service"]); mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]); - mockApp.service.andCallFake(function (name, value) { + mockApp.service.and.callFake(function (name, value) { var factory = value[value.length - 1]; registered[name] = { @@ -195,8 +195,8 @@ define( expect(mockApp.service).not.toHaveBeenCalled(); // Should have gotten one warning for each skipped component - expect(mockLog.warn.calls.length).toEqual(2); - expect(mockLog.info.calls.length).toEqual(1); + expect(mockLog.warn.calls.count()).toEqual(2); + expect(mockLog.info.calls.count()).toEqual(1); }); it("warns about and skips aggregators with zero providers", function () { diff --git a/platform/framework/test/resolve/BundleResolverSpec.js b/platform/framework/test/resolve/BundleResolverSpec.js index 0a99c7ed08..4909dc09bf 100644 --- a/platform/framework/test/resolve/BundleResolverSpec.js +++ b/platform/framework/test/resolve/BundleResolverSpec.js @@ -47,7 +47,7 @@ define( ["error", "warn", "info", "debug"] ); - mockExtensionResolver.resolve.andReturn(Promise.resolve("a")); + mockExtensionResolver.resolve.and.returnValue(Promise.resolve("a")); resolver = new BundleResolver( mockExtensionResolver, @@ -57,27 +57,11 @@ define( }); it("invokes the extension resolver for all bundle extensions", function () { - var result; - - resolver.resolveBundles([ + return resolver.resolveBundles([ new Bundle("x", { extensions: { tests: [{}, {}, {}] } }), new Bundle("y", { extensions: { tests: [{}, {}], others: [{}, {}] } }), new Bundle("z", { extensions: { others: [{}] } }) - ]).then(function (v) { - result = v; - }); - - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - // Should get back the result from the resolver, and - // should be binned by extension category. - runs(function () { + ]).then(function (result) { expect(result.tests).toEqual(["a", "a", "a", "a", "a"]); expect(result.others).toEqual(["a", "a", "a"]); }); diff --git a/platform/framework/test/resolve/ExtensionResolverSpec.js b/platform/framework/test/resolve/ExtensionResolverSpec.js index 628999eaaf..692be76497 100644 --- a/platform/framework/test/resolve/ExtensionResolverSpec.js +++ b/platform/framework/test/resolve/ExtensionResolverSpec.js @@ -46,7 +46,7 @@ define( ["error", "warn", "info", "debug"] ); - mockLoader.load.andReturn(Promise.resolve(Constructor)); + mockLoader.load.and.returnValue(Promise.resolve(Constructor)); resolver = new ExtensionResolver(mockLoader, mockLog); }); @@ -56,22 +56,9 @@ define( sources: "x", extensions: { tests: [{ implementation: "y/z.js" }] } }), - extension = bundle.getExtensions("tests")[0], - result; + extension = bundle.getExtensions("tests")[0]; - resolver.resolve(extension).then(function (v) { - result = v; - }); - - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { + return resolver.resolve(extension).then(function (result) { // Verify that the right file was requested expect(mockLoader.load).toHaveBeenCalledWith("w/x/y/z.js"); @@ -90,26 +77,13 @@ define( implementation: "y/z.js" }] } }), - extension = bundle.getExtensions("tests")[0], - result; + extension = bundle.getExtensions("tests")[0]; - mockLoader.load.andReturn(Promise.reject(new Error("test error"))); - resolver.resolve(extension).then(function (v) { - result = v; - }); + mockLoader.load.and.returnValue(Promise.reject(new Error("test error"))); - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { + return resolver.resolve(extension).then(function (result) { // Should have gotten a warning expect(mockLog.warn).toHaveBeenCalled(); - // We should have resolved to the plain definition from above expect(typeof result).not.toEqual('function'); expect(result.someOtherKey).toEqual("some other value"); @@ -121,25 +95,11 @@ define( sources: "x", extensions: { tests: [{ implementation: "y/z.js" }] } }), - extension = bundle.getExtensions("tests")[0], - result; + extension = bundle.getExtensions("tests")[0]; - resolver.resolve(extension).then(function (v) { - result = v; - }); - - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { + return resolver.resolve(extension).then(function (result) { // Verify that the right file was requested expect(mockLoader.load).toHaveBeenCalledWith("w/x/y/z.js"); - // We should have resolved to the constructor from above expect(typeof result).toEqual('function'); expect(result().someKey).toEqual("some value"); diff --git a/platform/framework/test/resolve/ImplementationLoaderSpec.js b/platform/framework/test/resolve/ImplementationLoaderSpec.js index b052e75c16..e16cfae09a 100644 --- a/platform/framework/test/resolve/ImplementationLoaderSpec.js +++ b/platform/framework/test/resolve/ImplementationLoaderSpec.js @@ -50,28 +50,14 @@ define( }); it("wraps require results in a Promise that can resolve", function () { - var result; - // Load and get the result - loader.load("xyz.js").then(function (v) { - result = v; + var promise = loader.load("xyz.js").then(function (result) { + expect(result).toEqual("test result"); }); - expect(result).toBeUndefined(); - required.fulfill("test result"); - waitsFor( - function () { - return result !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { - expect(result).toEqual("test result"); - }); + return promise; }); it("wraps require results in a Promise that can reject", function () { @@ -79,28 +65,19 @@ define( rejection; // Load and get the result - loader.load("xyz.js").then( + var promise = loader.load("xyz.js").then( function (v) { result = v; }, function (v) { rejection = v; - } - ); + }); expect(result).toBeUndefined(); required.reject("test result"); - waitsFor( - function () { - return rejection !== undefined; - }, - "promise resolution", - 250 - ); - - runs(function () { + return promise.then(function () { expect(result).toBeUndefined(); expect(rejection).toEqual("test result"); }); diff --git a/platform/identity/test/IdentityAggregatorSpec.js b/platform/identity/test/IdentityAggregatorSpec.js index 45706b50ff..8c4b7aa30d 100644 --- a/platform/identity/test/IdentityAggregatorSpec.js +++ b/platform/identity/test/IdentityAggregatorSpec.js @@ -28,14 +28,9 @@ define( var mockProviders, mockQ, resolves, - mockCallback, testUsers, aggregator; - function callbackCalled() { - return mockCallback.calls.length > 0; - } - function resolveProviderPromises() { ['a', 'b', 'c'].forEach(function (id, i) { resolves[id](testUsers[i]); @@ -57,7 +52,7 @@ define( ['getUser'] ); - mockProvider.getUser.andReturn(new Promise(function (r) { + mockProvider.getUser.and.returnValue(new Promise(function (r) { resolves[id] = r; })); @@ -65,12 +60,10 @@ define( }); mockQ = jasmine.createSpyObj('$q', ['all']); - mockQ.all.andCallFake(function (promises) { + mockQ.all.and.callFake(function (promises) { return Promise.all(promises); }); - mockCallback = jasmine.createSpy('callback'); - aggregator = new IdentityAggregator( mockQ, mockProviders @@ -91,47 +84,44 @@ define( }); it("returns the first result when it is defined", function () { - aggregator.getUser().then(mockCallback); + var promise = aggregator.getUser(); resolveProviderPromises(); - waitsFor(callbackCalled); - runs(function () { - expect(mockCallback).toHaveBeenCalledWith(testUsers[0]); + return promise.then(function (user) { + expect(user).toEqual(testUsers[0]); }); }); it("returns a later result when earlier results are undefined", function () { testUsers[0] = undefined; - aggregator.getUser().then(mockCallback); + var promise = aggregator.getUser(); resolveProviderPromises(); - waitsFor(callbackCalled); - runs(function () { - expect(mockCallback).toHaveBeenCalledWith(testUsers[1]); + return promise.then(function (user) { + expect(user).toEqual(testUsers[1]); }); }); it("returns undefined when no providers expose users", function () { testUsers = [undefined, undefined, undefined]; - aggregator.getUser().then(mockCallback); + var promise = aggregator.getUser(); resolveProviderPromises(); - waitsFor(callbackCalled); - runs(function () { - expect(mockCallback).toHaveBeenCalledWith(undefined); + return promise.then(function (user) { + expect(user).toBe(undefined); }); }); it("returns undefined when there are no providers", function () { - new IdentityAggregator(mockQ, []).getUser().then(mockCallback); - waitsFor(callbackCalled); - runs(function () { - expect(mockCallback).toHaveBeenCalledWith(undefined); + var promise = new IdentityAggregator(mockQ, []).getUser(); + + return promise.then(function (user) { + expect(user).toBe(undefined); }); }); diff --git a/platform/identity/test/IdentityCreationDecoratorSpec.js b/platform/identity/test/IdentityCreationDecoratorSpec.js index 3b3f4ff043..3b39cc44b3 100644 --- a/platform/identity/test/IdentityCreationDecoratorSpec.js +++ b/platform/identity/test/IdentityCreationDecoratorSpec.js @@ -32,15 +32,9 @@ define( mockCreationService, mockParent, mockCreatedObject, - mockCallback, decorator; - function calledBack() { - return mockCallback.calls.length > 0; - } - beforeEach(function () { - mockCallback = jasmine.createSpy('callback'); mockIdentityService = jasmine.createSpyObj( 'identityService', ['getUser'] @@ -58,10 +52,10 @@ define( ['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability'] ); mockCreationService.createObject - .andReturn(Promise.resolve(mockCreatedObject)); + .and.returnValue(Promise.resolve(mockCreatedObject)); mockIdentityService.getUser - .andReturn(Promise.resolve({ key: "test-user-id" })); - mockParent.getId.andReturn('test-id'); + .and.returnValue(Promise.resolve({ key: "test-user-id" })); + mockParent.getId.and.returnValue('test-id'); decorator = new IdentityCreationDecorator( mockIdentityService, mockCreationService @@ -71,33 +65,27 @@ define( it("delegates to its decorated service when identity is available", function () { var testModel = { someKey: "some value" }; - decorator.createObject(testModel, mockParent) - .then(mockCallback); - - waitsFor(calledBack); - runs(function () { - expect(mockCallback) - .toHaveBeenCalledWith(mockCreatedObject); - }); + return decorator.createObject(testModel, mockParent) + .then(function (object) { + expect(object).toEqual(mockCreatedObject); + }); }); it("adds a creator property", function () { var testModel = { someKey: "some value" }; - decorator.createObject(testModel, mockParent) - .then(mockCallback); + return decorator.createObject(testModel, mockParent) + .then(function (object) { + expect(object) + .toEqual(mockCreatedObject); - waitsFor(calledBack); - runs(function () { - expect(mockCallback) - .toHaveBeenCalledWith(mockCreatedObject); - // Make sure arguments were delegated appropriately - expect(mockCreationService.createObject) + // Make sure arguments were delegated appropriately + expect(mockCreationService.createObject) .toHaveBeenCalledWith( { someKey: "some value", creator: "test-user-id" }, mockParent ); - }); + }); }); }); diff --git a/platform/identity/test/IdentityIndicatorSpec.js b/platform/identity/test/IdentityIndicatorSpec.js index f00b9332a4..9541b179c2 100644 --- a/platform/identity/test/IdentityIndicatorSpec.js +++ b/platform/identity/test/IdentityIndicatorSpec.js @@ -36,13 +36,13 @@ define( ['getUser'] ); - mockIdentityService.getUser.andReturn(mockPromise); + mockIdentityService.getUser.and.returnValue(mockPromise); indicator = new IdentityIndicator(mockIdentityService); }); it("shows information about the current user", function () { - mockPromise.then.mostRecentCall.args[0]({ + mockPromise.then.calls.mostRecent().args[0]({ key: "testuserid", name: "A User" }); @@ -59,7 +59,7 @@ define( }); it("shows nothing when there is no identity information", function () { - mockPromise.then.mostRecentCall.args[0](undefined); + mockPromise.then.calls.mostRecent().args[0](undefined); expect(indicator.getCssClass()).toBeUndefined(); expect(indicator.getText()).toBeUndefined(); expect(indicator.getDescription()).toBeUndefined(); diff --git a/platform/identity/test/IdentityProviderSpec.js b/platform/identity/test/IdentityProviderSpec.js index 70243ab920..7a658e1b4a 100644 --- a/platform/identity/test/IdentityProviderSpec.js +++ b/platform/identity/test/IdentityProviderSpec.js @@ -28,16 +28,11 @@ define( function (IdentityProvider) { describe("IdentityProvider", function () { - var mockQ, mockCallback, provider; - - function calledBack() { - return mockCallback.calls.length > 0; - } + var mockQ, provider; beforeEach(function () { - mockCallback = jasmine.createSpy('callback'); mockQ = jasmine.createSpyObj('$q', ['when']); - mockQ.when.andCallFake(function (v) { + mockQ.when.and.callFake(function (v) { return Promise.resolve(v); }); @@ -45,11 +40,8 @@ define( }); it("provides an undefined user", function () { - provider.getUser().then(mockCallback); - - waitsFor(calledBack); - runs(function () { - expect(mockCallback).toHaveBeenCalledWith(undefined); + return provider.getUser().then(function (user) { + expect(user).toBe(undefined); }); }); diff --git a/platform/import-export/test/actions/ExportAsJSONActionSpec.js b/platform/import-export/test/actions/ExportAsJSONActionSpec.js index 6eb82ba6ca..b179dde296 100644 --- a/platform/import-export/test/actions/ExportAsJSONActionSpec.js +++ b/platform/import-export/test/actions/ExportAsJSONActionSpec.js @@ -63,11 +63,11 @@ define( 'getType' ]); - mockType.hasFeature.andCallFake(function (feature) { + mockType.hasFeature.and.callFake(function (feature) { return feature === 'creation'; }); - typeService.getType.andReturn(mockType); + typeService.getType.and.returnValue(mockType); context = {}; context.domainObject = domainObjectFactory( @@ -78,11 +78,11 @@ define( invoke: invokeAdapter }} }); - identifierService.generate.andReturn('brandNewId'); - exportService.exportJSON.andCallFake(function (tree, options) { + identifierService.generate.and.returnValue('brandNewId'); + exportService.exportJSON.and.callFake(function (tree, options) { exportedTree = tree; }); - policyService.allow.andCallFake(function (capability, type) { + policyService.allow.and.callFake(function (capability, type) { return type.hasFeature(capability); }); @@ -107,7 +107,7 @@ define( } }; - typeService.getType.andReturn(nonCreatableType); + typeService.getType.and.returnValue(nonCreatableType); var parent = domainObjectFactory({ name: 'parent', @@ -126,19 +126,11 @@ define( context.domainObject = parent; addChild(child); - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Exported tree sohuld have been built"); - - runs(function () { + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { expect(Object.keys(action.tree).length).toBe(1); expect(action.tree.hasOwnProperty("parentId")) .toBeTruthy(); @@ -167,19 +159,11 @@ define( context.domainObject = parent; - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Exported tree sohuld have been built"); - - runs(function () { + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { expect(Object.keys(action.tree).length).toBe(2); expect(action.tree.hasOwnProperty("infiniteParentId")) .toBeTruthy(); @@ -210,19 +194,10 @@ define( context.domainObject = parent; - var init = false; - runs(function () { + return new Promise (function (resolve) { action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); - - waitsFor(function () { - return init; - }, "Exported tree should have been built"); - - runs(function () { + setTimeout(resolve, 100); + }).then(function () { expect(Object.keys(action.tree).length).toBe(2); expect(action.tree.hasOwnProperty('parentId')) .toBeTruthy(); @@ -233,19 +208,11 @@ define( }); it("exports object tree in the correct format", function () { - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Exported tree sohuld have been built"); - - runs(function () { + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { expect(Object.keys(exportedTree).length).toBe(2); expect(exportedTree.hasOwnProperty('openmct')).toBeTruthy(); expect(exportedTree.hasOwnProperty('rootId')).toBeTruthy(); diff --git a/platform/import-export/test/actions/ImportAsJSONActionSpec.js b/platform/import-export/test/actions/ImportAsJSONActionSpec.js index 236a793db0..305ab5cb3d 100644 --- a/platform/import-export/test/actions/ImportAsJSONActionSpec.js +++ b/platform/import-export/test/actions/ImportAsJSONActionSpec.js @@ -49,7 +49,7 @@ define( openmct = { $injector: jasmine.createSpyObj('$injector', ['get']) }; - mockInstantiate = jasmine.createSpy('instantiate').andCallFake( + mockInstantiate = jasmine.createSpy('instantiate').and.callFake( function (model, id) { var config = { "model": model, @@ -58,7 +58,7 @@ define( }; var locationCapability = { setPrimaryLocation: jasmine.createSpy - ('setPrimaryLocation').andCallFake( + ('setPrimaryLocation').and.callFake( function (newLocation) { config.model.location = newLocation; } @@ -68,9 +68,9 @@ define( if (model.composition) { var compCapability = jasmine.createSpy('compCapability') - .andReturn(model.composition); + .and.returnValue(model.composition); compCapability.add = jasmine.createSpy('add') - .andCallFake(function (newObj) { + .and.callFake(function (newObj) { config.model.composition.push(newObj.getId()); }); config.capabilities.composition = compCapability; @@ -78,7 +78,7 @@ define( newObjects.push(domainObjectFactory(config)); return domainObjectFactory(config); }); - openmct.$injector.get.andReturn(mockInstantiate); + openmct.$injector.get.and.returnValue(mockInstantiate); dialogService = jasmine.createSpyObj('dialogService', [ 'getUserInput', @@ -90,13 +90,13 @@ define( 'generate' ] ); - identifierService.generate.andCallFake(function () { + identifierService.generate.and.callFake(function () { uniqueId++; return uniqueId; }); compositionCapability = jasmine.createSpy('compositionCapability'); mockDialog = jasmine.createSpyObj("dialog", ["dismiss"]); - dialogService.showBlockingMessage.andReturn(mockDialog); + dialogService.showBlockingMessage.and.returnValue(mockDialog); action = new ImportAsJSONAction(exportService, identifierService, dialogService, openmct, context); @@ -121,7 +121,7 @@ define( }); it("displays error dialog on invalid file choice", function () { - dialogService.getUserInput.andReturn(Promise.resolve( + dialogService.getUserInput.and.returnValue(Promise.resolve( { selectFile: { body: JSON.stringify({badKey: "INVALID"}), @@ -130,26 +130,25 @@ define( }) ); - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Promise containing file data should have resolved"); - - runs(function () { + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { expect(dialogService.getUserInput).toHaveBeenCalled(); expect(dialogService.showBlockingMessage).toHaveBeenCalled(); }); }); it("can import self-containing objects", function () { - dialogService.getUserInput.andReturn(Promise.resolve( + var compDomainObject = domainObjectFactory({ + name: 'compObject', + model: { name: 'compObject'}, + capabilities: {"composition": compositionCapability} + }); + context.domainObject = compDomainObject; + + dialogService.getUserInput.and.returnValue(Promise.resolve( { selectFile: { body: JSON.stringify({ @@ -178,25 +177,17 @@ define( }) ); - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Promise containing file data should have resolved"); - - runs(function () { - expect(mockInstantiate.calls.length).toEqual(2); + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { + expect(mockInstantiate.calls.count()).toEqual(2); }); }); it("assigns new ids to each imported object", function () { - dialogService.getUserInput.andReturn(Promise.resolve( + dialogService.getUserInput.and.returnValue(Promise.resolve( { selectFile: { body: JSON.stringify({ @@ -217,20 +208,12 @@ define( }) ); - var init = false; - runs(function () { - action.perform(); - setTimeout(function () { - init = true; - }, 100); - }); + action.perform(); - waitsFor(function () { - return init; - }, "Promise containing file data should have resolved"); - - runs(function () { - expect(mockInstantiate.calls.length).toEqual(1); + return new Promise(function (resolve, reject) { + setTimeout(resolve, 100); + }).then(function () { + expect(mockInstantiate.calls.count()).toEqual(1); expect(newObjects[0].getId()).toBe('1'); }); }); diff --git a/platform/persistence/aggregator/test/PersistenceAggregatorSpec.js b/platform/persistence/aggregator/test/PersistenceAggregatorSpec.js index 97397ae3c5..564e6a4fab 100644 --- a/platform/persistence/aggregator/test/PersistenceAggregatorSpec.js +++ b/platform/persistence/aggregator/test/PersistenceAggregatorSpec.js @@ -60,14 +60,14 @@ define( PERSISTENCE_SERVICE_METHODS ); PERSISTENCE_SERVICE_METHODS.forEach(function (m) { - mockProvider[m].andReturn(fakePromise(true)); + mockProvider[m].and.returnValue(fakePromise(true)); }); - mockProvider.listSpaces.andReturn(fakePromise([space])); + mockProvider.listSpaces.and.returnValue(fakePromise([space])); return mockProvider; }); mockCallback = jasmine.createSpy(); - mockQ.all.andCallFake(function (fakePromises) { + mockQ.all.and.callFake(function (fakePromises) { var result = []; fakePromises.forEach(function (p) { p.then(function (v) { diff --git a/platform/persistence/couch/test/CouchIndicatorSpec.js b/platform/persistence/couch/test/CouchIndicatorSpec.js index 9cf3c26808..5782c9121f 100644 --- a/platform/persistence/couch/test/CouchIndicatorSpec.js +++ b/platform/persistence/couch/test/CouchIndicatorSpec.js @@ -39,7 +39,7 @@ define( testPath = "/test/path"; testInterval = 12321; // Some number - mockHttp.get.andReturn(mockPromise); + mockHttp.get.and.returnValue(mockPromise); indicator = new CouchIndicator( mockHttp, @@ -71,7 +71,7 @@ define( // Nominal just means getting back an object, without // an error field. - mockPromise.then.mostRecentCall.args[0]({ data: {} }); + mockPromise.then.calls.mostRecent().args[0]({ data: {} }); // Verify that these values changed; // don't test for specific text. @@ -90,7 +90,7 @@ define( // Nominal just means getting back an object, with // an error field. - mockPromise.then.mostRecentCall.args[0]( + mockPromise.then.calls.mostRecent().args[0]( { data: { error: "Uh oh." } } ); @@ -112,7 +112,7 @@ define( // Nominal just means getting back an object, without // an error field. - mockPromise.then.mostRecentCall.args[1]({ data: {} }); + mockPromise.then.calls.mostRecent().args[1]({ data: {} }); // Verify that these values changed; // don't test for specific text. diff --git a/platform/persistence/couch/test/CouchPersistenceProviderSpec.js b/platform/persistence/couch/test/CouchPersistenceProviderSpec.js index 971efd76f1..d2f9084802 100644 --- a/platform/persistence/couch/test/CouchPersistenceProviderSpec.js +++ b/platform/persistence/couch/test/CouchPersistenceProviderSpec.js @@ -47,7 +47,7 @@ define( mockHttp = jasmine.createSpy("$http"); mockQ = jasmine.createSpyObj("$q", ["when"]); - mockQ.when.andCallFake(mockPromise); + mockQ.when.and.callFake(mockPromise); // Capture promise results capture = jasmine.createSpy("capture"); @@ -70,20 +70,21 @@ define( // would expect, and finally verify that CouchPersistenceProvider's // return values match what is expected. it("lists all available documents", function () { - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { rows: [{ id: "a" }, { id: "b" }, { id: "c" }] } })); provider.listObjects().then(capture); expect(mockHttp).toHaveBeenCalledWith({ url: "/test/db/_all_docs", // couch document listing - method: "GET" + method: "GET", + data: undefined }); expect(capture).toHaveBeenCalledWith(["a", "b", "c"]); }); it("allows object creation", function () { var model = { someKey: "some value" }; - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "xyz", "ok": true } })); provider.createObject("testSpace", "abc", model).then(capture); @@ -92,6 +93,8 @@ define( method: "PUT", data: { "_id": "abc", + "_rev": undefined, + "_deleted": undefined, metadata: jasmine.any(Object), model: model } @@ -101,13 +104,14 @@ define( it("allows object models to be read back", function () { var model = { someKey: "some value" }; - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "xyz", "model": model } })); provider.readObject("testSpace", "abc").then(capture); expect(mockHttp).toHaveBeenCalledWith({ url: "/test/db/abc", - method: "GET" + method: "GET", + data: undefined }); expect(capture).toHaveBeenCalledWith(model); }); @@ -116,13 +120,13 @@ define( var model = { someKey: "some value" }; // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "xyz", "model": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "uvw", "ok": true } })); provider.updateObject("testSpace", "abc", model).then(capture); @@ -132,6 +136,7 @@ define( data: { "_id": "abc", "_rev": "xyz", + "_deleted": undefined, metadata: jasmine.any(Object), model: model } @@ -141,13 +146,13 @@ define( it("allows object deletion", function () { // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "xyz", "model": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "uvw", "ok": true } })); provider.deleteObject("testSpace", "abc", {}).then(capture); @@ -167,7 +172,7 @@ define( it("reports failure to create objects", function () { var model = { someKey: "some value" }; - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_rev": "xyz", "ok": false } })); provider.createObject("testSpace", "abc", model).then(capture); @@ -176,7 +181,7 @@ define( it("returns undefined when objects are not found", function () { // Act like a 404 - mockHttp.andReturn({ + mockHttp.and.returnValue({ then: function (success, fail) { return mockPromise(fail()); } diff --git a/platform/persistence/elastic/test/ElasticIndicatorSpec.js b/platform/persistence/elastic/test/ElasticIndicatorSpec.js index 12f6d794f4..2abeb2a9cf 100644 --- a/platform/persistence/elastic/test/ElasticIndicatorSpec.js +++ b/platform/persistence/elastic/test/ElasticIndicatorSpec.js @@ -39,7 +39,7 @@ define( testPath = "/test/path"; testInterval = 12321; // Some number - mockHttp.get.andReturn(mockPromise); + mockHttp.get.and.returnValue(mockPromise); indicator = new ElasticIndicator( mockHttp, @@ -73,7 +73,7 @@ define( // Nominal just means getting back an object, without // an error field. - mockPromise.then.mostRecentCall.args[0]({ data: {} }); + mockPromise.then.calls.mostRecent().args[0]({ data: {} }); // Verify that these values changed; // don't test for specific text. @@ -92,7 +92,7 @@ define( // Nominal just means getting back an object, without // an error field. - mockPromise.then.mostRecentCall.args[1]({ data: {} }); + mockPromise.then.calls.mostRecent().args[1]({ data: {} }); // Verify that these values changed; // don't test for specific text. diff --git a/platform/persistence/elastic/test/ElasticPersistenceProviderSpec.js b/platform/persistence/elastic/test/ElasticPersistenceProviderSpec.js index d719a5db42..fd641c6d08 100644 --- a/platform/persistence/elastic/test/ElasticPersistenceProviderSpec.js +++ b/platform/persistence/elastic/test/ElasticPersistenceProviderSpec.js @@ -46,8 +46,8 @@ define( mockHttp = jasmine.createSpy("$http"); mockQ = jasmine.createSpyObj("$q", ["when", "reject"]); - mockQ.when.andCallFake(mockPromise); - mockQ.reject.andCallFake(function (value) { + mockQ.when.and.callFake(mockPromise); + mockQ.reject.and.callFake(function (value) { return { then: function (ignored, callback) { return mockPromise(callback(value)); @@ -84,27 +84,30 @@ define( it("allows object creation", function () { var model = { someKey: "some value" }; - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 1 } })); provider.createObject("testSpace", "abc", model).then(capture); expect(mockHttp).toHaveBeenCalledWith({ url: "/test/db/abc", method: "PUT", - data: model + data: model, + params: undefined }); - expect(capture.mostRecentCall.args[0]).toBeTruthy(); + expect(capture.calls.mostRecent().args[0]).toBeTruthy(); }); it("allows object models to be read back", function () { var model = { someKey: "some value" }; - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 1, "_source": model } })); provider.readObject("testSpace", "abc").then(capture); expect(mockHttp).toHaveBeenCalledWith({ url: "/test/db/abc", - method: "GET" + method: "GET", + params: undefined, + data: undefined }); expect(capture).toHaveBeenCalledWith(model); }); @@ -113,13 +116,13 @@ define( var model = { someKey: "some value" }; // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 42, "_source": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 43, "_source": {} } })); provider.updateObject("testSpace", "abc", model).then(capture); @@ -129,31 +132,33 @@ define( params: { version: 42 }, data: model }); - expect(capture.mostRecentCall.args[0]).toBeTruthy(); + expect(capture.calls.mostRecent().args[0]).toBeTruthy(); }); it("allows object deletion", function () { // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 42, "_source": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 42, "_source": {} } })); provider.deleteObject("testSpace", "abc", {}).then(capture); expect(mockHttp).toHaveBeenCalledWith({ url: "/test/db/abc", - method: "DELETE" + method: "DELETE", + params: undefined, + data: undefined }); - expect(capture.mostRecentCall.args[0]).toBeTruthy(); + expect(capture.calls.mostRecent().args[0]).toBeTruthy(); }); it("returns undefined when objects are not found", function () { // Act like a 404 - mockHttp.andReturn({ + mockHttp.and.returnValue({ then: function (success, fail) { return mockPromise(fail()); } @@ -167,13 +172,13 @@ define( mockErrorCallback = jasmine.createSpy('error'); // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 42, "_source": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "status": 409, "error": "Revision error..." } })); provider.updateObject("testSpace", "abc", model).then( @@ -190,13 +195,13 @@ define( mockErrorCallback = jasmine.createSpy('error'); // First do a read to populate rev tags... - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "_id": "abc", "_version": 42, "_source": {} } })); provider.readObject("testSpace", "abc"); // Now perform an update - mockHttp.andReturn(mockPromise({ + mockHttp.and.returnValue(mockPromise({ data: { "status": 410, "error": "Revision error..." } })); provider.updateObject("testSpace", "abc", model).then( diff --git a/platform/persistence/elastic/test/ElasticSearchProviderSpec.js b/platform/persistence/elastic/test/ElasticSearchProviderSpec.js index 06df94f791..d8698be6cf 100644 --- a/platform/persistence/elastic/test/ElasticSearchProviderSpec.js +++ b/platform/persistence/elastic/test/ElasticSearchProviderSpec.js @@ -43,10 +43,10 @@ define([ describe('query', function () { beforeEach(function () { - spyOn(provider, 'cleanTerm').andReturn('cleanedTerm'); - spyOn(provider, 'fuzzyMatchUnquotedTerms').andReturn('fuzzy'); - spyOn(provider, 'parseResponse').andReturn('parsedResponse'); - $http.andReturn(Promise.resolve({})); + spyOn(provider, 'cleanTerm').and.returnValue('cleanedTerm'); + spyOn(provider, 'fuzzyMatchUnquotedTerms').and.returnValue('fuzzy'); + spyOn(provider, 'parseResponse').and.returnValue('parsedResponse'); + $http.and.returnValue(Promise.resolve({})); }); it('cleans terms and adds fuzzyness', function () { @@ -69,40 +69,28 @@ define([ }); it('gracefully fails when http fails', function () { - var promiseChainResolved = false; - $http.andReturn(Promise.reject()); + $http.and.returnValue(Promise.reject()); - provider + return provider .query('hello', 10) .then(function (results) { expect(results).toEqual({ hits: [], total: 0 }); - promiseChainResolved = true; }); - - waitsFor(function () { - return promiseChainResolved; - }); }); it('parses and returns when http succeeds', function () { - var promiseChainResolved = false; - $http.andReturn(Promise.resolve('successResponse')); + $http.and.returnValue(Promise.resolve('successResponse')); - provider + return provider .query('hello', 10) .then(function (results) { expect(provider.parseResponse) .toHaveBeenCalledWith('successResponse'); expect(results).toBe('parsedResponse'); - promiseChainResolved = true; }); - - waitsFor(function () { - return promiseChainResolved; - }); }); }); diff --git a/platform/persistence/local/test/LocalStoragePersistenceProviderSpec.js b/platform/persistence/local/test/LocalStoragePersistenceProviderSpec.js index df2887d177..f6ee1ff99b 100644 --- a/platform/persistence/local/test/LocalStoragePersistenceProviderSpec.js +++ b/platform/persistence/local/test/LocalStoragePersistenceProviderSpec.js @@ -46,7 +46,7 @@ define( mockQ = jasmine.createSpyObj("$q", ["when", "reject"]); mockCallback = jasmine.createSpy('callback'); - mockQ.when.andCallFake(mockPromise); + mockQ.when.and.callFake(mockPromise); provider = new LocalStoragePersistenceProvider( { localStorage: testLocalStorage }, @@ -62,10 +62,10 @@ define( it("lists all available documents", function () { provider.listObjects(testSpace).then(mockCallback); - expect(mockCallback.mostRecentCall.args[0]).toEqual([]); + expect(mockCallback.calls.mostRecent().args[0]).toEqual([]); provider.createObject(testSpace, 'abc', { a: 42 }); provider.listObjects(testSpace).then(mockCallback); - expect(mockCallback.mostRecentCall.args[0]).toEqual(['abc']); + expect(mockCallback.calls.mostRecent().args[0]).toEqual(['abc']); }); it("allows object creation", function () { @@ -74,7 +74,7 @@ define( .then(mockCallback); expect(JSON.parse(testLocalStorage[testSpace]).abc) .toEqual(model); - expect(mockCallback.mostRecentCall.args[0]).toBeTruthy(); + expect(mockCallback.calls.mostRecent().args[0]).toBeTruthy(); }); it("allows object models to be read back", function () { diff --git a/platform/persistence/queue/test/PersistenceFailureHandlerSpec.js b/platform/persistence/queue/test/PersistenceFailureHandlerSpec.js index 489c8abcc7..82c24feaf1 100644 --- a/platform/persistence/queue/test/PersistenceFailureHandlerSpec.js +++ b/platform/persistence/queue/test/PersistenceFailureHandlerSpec.js @@ -53,10 +53,10 @@ define( 'domainObject', ['getCapability', 'useCapability', 'getModel'] ); - mockFailure.domainObject.getCapability.andCallFake(function (c) { + mockFailure.domainObject.getCapability.and.callFake(function (c) { return (c === 'persistence') && mockPersistence; }); - mockFailure.domainObject.getModel.andReturn({ id: id, modified: index }); + mockFailure.domainObject.getModel.and.returnValue({ id: id, modified: index }); mockFailure.persistence = mockPersistence; mockFailure.id = id; mockFailure.error = { key: Constants.REVISION_ERROR_KEY }; @@ -68,9 +68,9 @@ define( mockDialogService = jasmine.createSpyObj('dialogService', ['getUserChoice']); mockFailures = ['a', 'b', 'c'].map(makeMockFailure); mockPromise = jasmine.createSpyObj('promise', ['then']); - mockDialogService.getUserChoice.andReturn(mockPromise); - mockQ.all.andReturn(mockPromise); - mockPromise.then.andReturn(mockPromise); + mockDialogService.getUserChoice.and.returnValue(mockPromise); + mockQ.all.and.returnValue(mockPromise); + mockPromise.then.and.returnValue(mockPromise); handler = new PersistenceFailureHandler(mockQ, mockDialogService); }); @@ -80,10 +80,10 @@ define( }); it("overwrites on request", function () { - mockQ.all.andReturn(asPromise([])); + mockQ.all.and.returnValue(asPromise([])); handler.handle(mockFailures); // User chooses overwrite - mockPromise.then.mostRecentCall.args[0](Constants.OVERWRITE_KEY); + mockPromise.then.calls.mostRecent().args[0](Constants.OVERWRITE_KEY); // Should refresh, remutate, and requeue all objects mockFailures.forEach(function (mockFailure, i) { expect(mockFailure.persistence.refresh).toHaveBeenCalled(); @@ -93,16 +93,16 @@ define( jasmine.any(Function), i // timestamp ); - expect(mockFailure.domainObject.useCapability.mostRecentCall.args[1]()) + expect(mockFailure.domainObject.useCapability.calls.mostRecent().args[1]()) .toEqual({ id: mockFailure.id, modified: i }); }); }); it("discards on request", function () { - mockQ.all.andReturn(asPromise([])); + mockQ.all.and.returnValue(asPromise([])); handler.handle(mockFailures); // User chooses overwrite - mockPromise.then.mostRecentCall.args[0](false); + mockPromise.then.calls.mostRecent().args[0](false); // Should refresh, but not remutate, and requeue all objects mockFailures.forEach(function (mockFailure) { expect(mockFailure.persistence.refresh).toHaveBeenCalled(); diff --git a/platform/persistence/queue/test/PersistenceQueueHandlerSpec.js b/platform/persistence/queue/test/PersistenceQueueHandlerSpec.js index 212fe18679..109298f442 100644 --- a/platform/persistence/queue/test/PersistenceQueueHandlerSpec.js +++ b/platform/persistence/queue/test/PersistenceQueueHandlerSpec.js @@ -49,7 +49,7 @@ define( 'persistence-' + id, ['persist', 'refresh'] ); - mockPersistence.persist.andReturn(asPromise(true)); + mockPersistence.persist.and.returnValue(asPromise(true)); return mockPersistence; } @@ -58,7 +58,7 @@ define( 'domainObject-' + id, ['getId'] ); - mockDomainObject.getId.andReturn(id); + mockDomainObject.getId.and.returnValue(id); return mockDomainObject; } @@ -73,8 +73,8 @@ define( mockDomainObjects[id] = makeMockDomainObject(id); }); mockRejection = jasmine.createSpyObj('rejection', ['then']); - mockQ.all.andReturn(asPromise([])); - mockRejection.then.andCallFake(function (callback, fallback) { + mockQ.all.and.returnValue(asPromise([])); + mockRejection.then.and.callFake(function (callback, fallback) { return asPromise(fallback({ someKey: "some value" })); }); handler = new PersistenceQueueHandler(mockQ, mockFailureHandler); @@ -90,8 +90,8 @@ define( }); it("handles failures that occur", function () { - mockPersistences.b.persist.andReturn(mockRejection); - mockPersistences.c.persist.andReturn(mockRejection); + mockPersistences.b.persist.and.returnValue(mockRejection); + mockPersistences.c.persist.and.returnValue(mockRejection); handler.persist(mockPersistences, mockDomainObjects, mockQueue); expect(mockFailureHandler.handle).toHaveBeenCalledWith([ { @@ -115,14 +115,14 @@ define( // This method is needed by PersistenceFailureHandler // to allow requeuing of objects for persistence when // Overwrite is chosen. - mockPersistences.b.persist.andReturn(mockRejection); + mockPersistences.b.persist.and.returnValue(mockRejection); handler.persist(mockPersistences, mockDomainObjects, mockQueue); // Verify precondition expect(mockQueue.put).not.toHaveBeenCalled(); // Invoke requeue - mockFailureHandler.handle.mostRecentCall.args[0][0].requeue(); + mockFailureHandler.handle.calls.mostRecent().args[0][0].requeue(); // Should have returned the object to the queue expect(mockQueue.put).toHaveBeenCalledWith( diff --git a/platform/persistence/queue/test/PersistenceQueueImplSpec.js b/platform/persistence/queue/test/PersistenceQueueImplSpec.js index d87f1b4afb..474b69a3b0 100644 --- a/platform/persistence/queue/test/PersistenceQueueImplSpec.js +++ b/platform/persistence/queue/test/PersistenceQueueImplSpec.js @@ -40,7 +40,7 @@ define( 'domainObject-' + id, ['getId'] ); - mockDomainObject.getId.andReturn(id); + mockDomainObject.getId.and.returnValue(id); return mockDomainObject; } @@ -59,10 +59,10 @@ define( mockDeferred = jasmine.createSpyObj('deferred', ['resolve']); mockDeferred.promise = jasmine.createSpyObj('promise', ['then']); mockPromise = jasmine.createSpyObj('promise', ['then']); - mockQ.defer.andReturn(mockDeferred); - mockTimeout.andReturn({}); - mockHandler.persist.andReturn(mockPromise); - mockPromise.then.andReturn(mockPromise); + mockQ.defer.and.returnValue(mockDeferred); + mockTimeout.and.returnValue({}); + mockHandler.persist.and.returnValue(mockPromise); + mockPromise.then.and.returnValue(mockPromise); queue = new PersistenceQueueImpl( mockQ, mockTimeout, @@ -87,7 +87,7 @@ define( queue.put(makeMockDomainObject('a'), makeMockPersistence('a')); queue.put(makeMockDomainObject('b'), makeMockPersistence('b')); queue.put(makeMockDomainObject('c'), makeMockPersistence('c')); - expect(mockTimeout.calls.length).toEqual(1); + expect(mockTimeout.calls.count()).toEqual(1); }); it("returns a promise", function () { @@ -99,14 +99,14 @@ define( // Keep adding objects to the queue between timeouts. // Should keep scheduling timeouts instead of resolving. queue.put(makeMockDomainObject('a'), makeMockPersistence('a')); - expect(mockTimeout.calls.length).toEqual(1); - mockTimeout.mostRecentCall.args[0](); + expect(mockTimeout.calls.count()).toEqual(1); + mockTimeout.calls.mostRecent().args[0](); queue.put(makeMockDomainObject('b'), makeMockPersistence('b')); - expect(mockTimeout.calls.length).toEqual(2); - mockTimeout.mostRecentCall.args[0](); + expect(mockTimeout.calls.count()).toEqual(2); + mockTimeout.calls.mostRecent().args[0](); queue.put(makeMockDomainObject('c'), makeMockPersistence('c')); - expect(mockTimeout.calls.length).toEqual(3); - mockTimeout.mostRecentCall.args[0](); + expect(mockTimeout.calls.count()).toEqual(3); + mockTimeout.calls.mostRecent().args[0](); expect(mockHandler.persist).not.toHaveBeenCalled(); }); @@ -115,8 +115,8 @@ define( queue.put(makeMockDomainObject('a'), makeMockPersistence('a')); queue.put(makeMockDomainObject('b'), makeMockPersistence('b')); queue.put(makeMockDomainObject('c'), makeMockPersistence('c')); - mockTimeout.mostRecentCall.args[0](); - mockTimeout.mostRecentCall.args[0](); + mockTimeout.calls.mostRecent().args[0](); + mockTimeout.calls.mostRecent().args[0](); expect(mockHandler.persist).toHaveBeenCalled(); }); @@ -124,28 +124,28 @@ define( // Persist some objects queue.put(makeMockDomainObject('a'), makeMockPersistence('a')); queue.put(makeMockDomainObject('b'), makeMockPersistence('b')); - mockTimeout.mostRecentCall.args[0](); - mockTimeout.mostRecentCall.args[0](); - expect(mockTimeout.calls.length).toEqual(2); + mockTimeout.calls.mostRecent().args[0](); + mockTimeout.calls.mostRecent().args[0](); + expect(mockTimeout.calls.count()).toEqual(2); // Adding a new object should not trigger a new timeout, // because we haven't completed the previous flush queue.put(makeMockDomainObject('c'), makeMockPersistence('c')); - expect(mockTimeout.calls.length).toEqual(2); + expect(mockTimeout.calls.count()).toEqual(2); }); it("clears the active flush after it has completed", function () { // Persist some objects queue.put(makeMockDomainObject('a'), makeMockPersistence('a')); queue.put(makeMockDomainObject('b'), makeMockPersistence('b')); - mockTimeout.mostRecentCall.args[0](); - mockTimeout.mostRecentCall.args[0](); - expect(mockTimeout.calls.length).toEqual(2); + mockTimeout.calls.mostRecent().args[0](); + mockTimeout.calls.mostRecent().args[0](); + expect(mockTimeout.calls.count()).toEqual(2); // Resolve the promise from handler.persist - mockPromise.then.calls[0].args[0](true); + mockPromise.then.calls.all()[0].args[0](true); // Adding a new object should now trigger a new timeout, // because we have completed the previous flush queue.put(makeMockDomainObject('c'), makeMockPersistence('c')); - expect(mockTimeout.calls.length).toEqual(3); + expect(mockTimeout.calls.count()).toEqual(3); }); }); } diff --git a/platform/persistence/queue/test/QueuingPersistenceCapabilityDecoratorSpec.js b/platform/persistence/queue/test/QueuingPersistenceCapabilityDecoratorSpec.js index 800ebcc312..c5ced2faea 100644 --- a/platform/persistence/queue/test/QueuingPersistenceCapabilityDecoratorSpec.js +++ b/platform/persistence/queue/test/QueuingPersistenceCapabilityDecoratorSpec.js @@ -53,10 +53,10 @@ define( ['getId'] ); - mockCapabilityService.getCapabilities.andReturn({ + mockCapabilityService.getCapabilities.and.returnValue({ persistence: mockPersistenceConstructor }); - mockPersistenceConstructor.andReturn(mockPersistence); + mockPersistenceConstructor.and.returnValue(mockPersistence); decorator = new QueuingPersistenceCapabilityDecorator( mockQueue, diff --git a/platform/policy/test/PolicyActionDecoratorSpec.js b/platform/policy/test/PolicyActionDecoratorSpec.js index c35e82d8bb..a14c39b5e8 100644 --- a/platform/policy/test/PolicyActionDecoratorSpec.js +++ b/platform/policy/test/PolicyActionDecoratorSpec.js @@ -51,8 +51,8 @@ define( ]; testContext = { someKey: "some value" }; - mockActionService.getActions.andReturn(testActions); - mockPolicyService.allow.andReturn(true); + mockActionService.getActions.and.returnValue(testActions); + mockPolicyService.allow.and.returnValue(true); decorator = new PolicyActionDecorator( mockPolicyService, @@ -86,7 +86,7 @@ define( it("filters out policy-disallowed actions", function () { // Disallow the second action - mockPolicyService.allow.andCallFake(function (cat, candidate) { + mockPolicyService.allow.and.callFake(function (cat, candidate) { return candidate.someKey !== 'b'; }); expect(decorator.getActions(testContext)) diff --git a/platform/policy/test/PolicyProviderSpec.js b/platform/policy/test/PolicyProviderSpec.js index 1954e5dbaa..49dc355674 100644 --- a/platform/policy/test/PolicyProviderSpec.js +++ b/platform/policy/test/PolicyProviderSpec.js @@ -43,14 +43,14 @@ define( ]; mockPolicies = testPolicies.map(function (p) { var mockPolicy = jasmine.createSpyObj("policy", ['allow']); - mockPolicy.allow.andCallFake(function () { + mockPolicy.allow.and.callFake(function () { return p.result; }); return mockPolicy; }); mockPolicyConstructors = testPolicies.map(function (p, i) { var mockPolicyConstructor = jasmine.createSpy(); - mockPolicyConstructor.andReturn(mockPolicies[i]); + mockPolicyConstructor.and.returnValue(mockPolicies[i]); mockPolicyConstructor.message = p.message; mockPolicyConstructor.category = p.category; return mockPolicyConstructor; diff --git a/platform/policy/test/PolicyViewDecoratorSpec.js b/platform/policy/test/PolicyViewDecoratorSpec.js index a90f01e848..926175c668 100644 --- a/platform/policy/test/PolicyViewDecoratorSpec.js +++ b/platform/policy/test/PolicyViewDecoratorSpec.js @@ -54,9 +54,9 @@ define( { someKey: "c" } ]; - mockDomainObject.getId.andReturn('xyz'); - mockViewService.getViews.andReturn(testViews); - mockPolicyService.allow.andReturn(true); + mockDomainObject.getId.and.returnValue('xyz'); + mockViewService.getViews.and.returnValue(testViews); + mockPolicyService.allow.and.returnValue(true); decorator = new PolicyViewDecorator( mockPolicyService, @@ -90,7 +90,7 @@ define( it("filters out policy-disallowed views", function () { // Disallow the second action - mockPolicyService.allow.andCallFake(function (cat, candidate) { + mockPolicyService.allow.and.callFake(function (cat, candidate) { return candidate.someKey !== 'b'; }); expect(decorator.getViews(mockDomainObject)) diff --git a/platform/representation/test/MCTIncludeSpec.js b/platform/representation/test/MCTIncludeSpec.js index a907a82b35..be72114d2d 100644 --- a/platform/representation/test/MCTIncludeSpec.js +++ b/platform/representation/test/MCTIncludeSpec.js @@ -37,7 +37,7 @@ define( mctInclude; function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -68,8 +68,8 @@ define( mockScope = jasmine.createSpyObj('$scope', ['$watch', '$on']); mockElement = jasmine.createSpyObj('element', ['empty']); mockChangeTemplate = jasmine.createSpy('changeTemplate'); - mockLinker.link.andReturn(mockChangeTemplate); - mockLinker.getPath.andCallFake(function (template) { + mockLinker.link.and.returnValue(mockChangeTemplate); + mockLinker.getPath.and.callFake(function (template) { return testUrls[template.key]; }); mctInclude = new MCTInclude(testTemplates, mockLinker); diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 50f68c3ee6..79ce12481d 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -56,7 +56,7 @@ define( } function fireWatch(expr, value) { - mockScope.$watch.calls.forEach(function (call) { + mockScope.$watch.calls.all().forEach(function (call) { if (call.args[0] === expr) { call.args[1](value); } @@ -107,7 +107,7 @@ define( "representer" + name, ["represent", "destroy"] ); - constructor.andReturn(representer); + constructor.and.returnValue(representer); return constructor; }); @@ -126,13 +126,13 @@ define( mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); - mockDomainObject.getModel.andReturn(testModel); - mockLinker.link.andReturn(mockChangeTemplate); - mockLinker.getPath.andCallFake(function (ext) { + mockDomainObject.getModel.and.returnValue(testModel); + mockLinker.link.and.returnValue(mockChangeTemplate); + mockLinker.getPath.and.callFake(function (ext) { return testUrls[ext.key]; }); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return c === 'mutation' && mockMutationCapability; }); @@ -212,7 +212,7 @@ define( mockScope.domainObject = mockDomainObject; // Trigger the watch - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); expect(mockDomainObject.useCapability) .toHaveBeenCalledWith("testCapability"); @@ -227,7 +227,7 @@ define( expect(mockLog.warn).not.toHaveBeenCalled(); // Trigger the watch - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); // Should have gotten a warning - that's an unknown key expect(mockLog.warn).toHaveBeenCalled(); @@ -236,17 +236,17 @@ define( it("clears out obsolete properties from scope", function () { mockScope.key = "def"; mockScope.domainObject = mockDomainObject; - mockDomainObject.useCapability.andReturn("some value"); + mockDomainObject.useCapability.and.returnValue("some value"); // Trigger the watch - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); expect(mockScope.testCapability).toBeDefined(); // Change the view mockScope.key = "xyz"; // Trigger the watch again; should clear capability from scope - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); expect(mockScope.testCapability).toBeUndefined(); }); @@ -268,38 +268,38 @@ define( DOMAIN_OBJECT_METHODS ); - mockDomainObject.getCapability.andCallFake(function (c) { + mockDomainObject.getCapability.and.callFake(function (c) { return { context: mockContext, mutation: mockMutationCapability }[c]; }); - mockLink.getCapability.andCallFake(function (c) { + mockLink.getCapability.and.callFake(function (c) { return { context: mockContext2, mutation: mockMutationCapability }[c]; }); - mockDomainObject.hasCapability.andCallFake(function (c) { + mockDomainObject.hasCapability.and.callFake(function (c) { return c === 'context'; }); - mockLink.hasCapability.andCallFake(function (c) { + mockLink.hasCapability.and.callFake(function (c) { return c === 'context'; }); - mockLink.getModel.andReturn({}); + mockLink.getModel.and.returnValue({}); - mockContext.getPath.andReturn([mockDomainObject]); - mockContext2.getPath.andReturn([mockParent, mockLink]); + mockContext.getPath.and.returnValue([mockDomainObject]); + mockContext2.getPath.and.returnValue([mockParent, mockLink]); - mockLink.getId.andReturn('test-id'); - mockDomainObject.getId.andReturn('test-id'); + mockLink.getId.and.returnValue('test-id'); + mockDomainObject.getId.and.returnValue('test-id'); - mockParent.getId.andReturn('parent-id'); + mockParent.getId.and.returnValue('parent-id'); mockScope.key = "abc"; mockScope.domainObject = mockDomainObject; - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); }); it("listens for mutation of that object", function () { @@ -308,19 +308,19 @@ define( }); it("detects subsequent changes among linked instances", function () { - var callCount = mockChangeTemplate.calls.length; + var callCount = mockChangeTemplate.calls.count(); mockScope.domainObject = mockLink; - mockScope.$watch.calls[0].args[1](); + mockScope.$watch.calls.all()[0].args[1](); - expect(mockChangeTemplate.calls.length) + expect(mockChangeTemplate.calls.count()) .toEqual(callCount + 1); }); it("does not trigger excess template changes for same instances", function () { - var callCount = mockChangeTemplate.calls.length; - mockScope.$watch.calls[0].args[1](); - expect(mockChangeTemplate.calls.length).toEqual(callCount); + var callCount = mockChangeTemplate.calls.count(); + mockScope.$watch.calls.all()[0].args[1](); + expect(mockChangeTemplate.calls.count()).toEqual(callCount); }); }); diff --git a/platform/representation/test/TemplateLinkerSpec.js b/platform/representation/test/TemplateLinkerSpec.js index 87cdf0a5c9..73431a2a97 100644 --- a/platform/representation/test/TemplateLinkerSpec.js +++ b/platform/representation/test/TemplateLinkerSpec.js @@ -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("