Update test specs to use Jasmine 3 (#2089)

* Updated Karma and Jasmine versions

* Added DOMObserver class. Supports promise-based testing of DOM changes

Update asynchronous test specs to use promises or done() instead of waitsFor/runs

* Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons

* Global find + replace to fix syntax issues

* Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality

* Addressed review comments

* Resolved merge conflicts with master

* Fixed style errors

* Use spy.calls.count() instead of manually tracking
This commit is contained in:
Andrew Henry
2018-06-29 17:32:59 -07:00
committed by Pete Richards
parent 013eba744d
commit 433dee0314
305 changed files with 2866 additions and 3324 deletions

View File

@@ -31,7 +31,7 @@ define(
function ControlledPromise() {
this.resolveHandlers = [];
this.rejectHandlers = [];
spyOn(this, 'then').andCallThrough();
spyOn(this, 'then').and.callThrough();
}

View File

@@ -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(

View File

@@ -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);
});

View File

@@ -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)

View File

@@ -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();
});

View File

@@ -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)

View File

@@ -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)

View File

@@ -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"
});

View File

@@ -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');
});

View File

@@ -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);
});
});

View File

@@ -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'),

View File

@@ -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);
});
});

View File

@@ -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();
});
});

View File

@@ -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);

View File

@@ -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();
});
});

View File

@@ -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);
});

View File

@@ -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();

View File

@@ -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 = {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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 () {