Spying on SceneController

25 views
Skip to first unread message

P. Douglas Reeder

unread,
Aug 26, 2010, 3:27:12 PM8/26/10
to jasmine-webos
It's not clear how to spy on the scene controller. When I write a
suite like


describe("details asst w/ no recur", function () {
var item;
var asst;

beforeEach(function(){
item = new Item({summaryText: "details setup", kind: Kind.STANDARD,
dueDate: Date.UTC(2010, 4, 28)});
asst = jasmine.webos.createStubSceneAssistant("details", item,
false);
asst.controller.stageController.assistant = {
appMenuAttr: Object.clone(Tracker.appMenuAttr),
appMenuModel: {visible: true, items:
Tracker.appMenuItemsBegin.concat(Tracker.appMenuItemsEnd)}
};
});

it("should set up models", function () {
Mojo.Log.info("asst.controller.stageController:",
Mojo.Log.propertiesAsString(asst.controller.stageController));
spyOn(jasmine.webos.StubSceneController, "popupSubmenu");
asst.setup();
expect(asst.controller.get("recurDiv").innerHTML).toEqual("No
Repeat");

//
expect(jasmine.webos.StubSceneController.popupSubmenu).toHaveBeenCalled();
});
});

I get the error "popupSubmenu() method does not exist", even if I add
a definition to jasmine-webos.js:

jasmine.webos.StubSceneController.prototype.popupSubmenu =
Mojo.doNothing;



A similar error happens if I try to spy on serviceRequest(), which is
already defined in jasmine-webos.js

Davis Frank

unread,
Aug 27, 2010, 7:59:10 AM8/27/10
to jasmin...@googlegroups.com
The "method does not exist" error, if the property is actually there, is most often due to spying later than when the method is added.

Have you tried spying on popupSubmenu in your beforeEach?

--dwf

P. Douglas Reeder

unread,
Aug 27, 2010, 11:39:39 AM8/27/10
to jasmine-webos
Moving spyOn to the beforeEach just makes it fail sooner (and makes
both specs fail):

describe("details asst w/ no recur", function () {
var item;
var asst;

beforeEach(function(){
spyOn(jasmine.webos.StubSceneController, "popupSubmenu");
item = new Item({summaryText: "details setup", kind: Kind.STANDARD,
dueDate: Date.UTC(2010, 4, 28)});
asst = jasmine.webos.createStubSceneAssistant("details", item,
false);
asst.controller.stageController.assistant = {
appMenuAttr: Object.clone(Tracker.appMenuAttr),
appMenuModel: {visible: true, items:
Tracker.appMenuItemsBegin.concat(Tracker.appMenuItemsEnd)}
};
});

it("should process create arguments", function () {
expect(asst.item.summaryText).toEqual(item.summaryText);
expect(asst.itemIsNew).toBeTruthy();
expect(asst.allowProjectChange).toBe(false);
});

it("should set up models", function () {
Mojo.Log.info("asst.controller.stageController:",
Mojo.Log.propertiesAsString(asst.controller.stageController));
asst.setup();
expect(asst.controller.get("recurDiv").innerHTML).toEqual("No
Repeat");

//
expect(jasmine.webos.StubSceneController.popupSubmenu).toHaveBeenCalled();
});
});


combining the beforeEach and specs doesn't help:

describe("spy test", function () {
var item;
var asst;

it("should set up spy without failing", function(){
spyOn(jasmine.webos.StubSceneController, "listen");
item = new Item({summaryText: "details setup", kind: Kind.STANDARD,
dueDate: Date.UTC(2010, 4, 28)});
asst = jasmine.webos.createStubSceneAssistant("details", item,
false);
asst.controller.stageController.assistant = {
appMenuAttr: Object.clone(Tracker.appMenuAttr),
appMenuModel: {visible: true, items:
Tracker.appMenuItemsBegin.concat(Tracker.appMenuItemsEnd)}
};

expect(asst.item.summaryText).toEqual(item.summaryText);
expect(asst.itemIsNew).toBeTruthy();
expect(asst.allowProjectChange).toBe(false);

asst.setup();
expect(asst.controller.get("recurDiv").innerHTML).toEqual("No
Repeat");

//
expect(jasmine.webos.StubSceneController.popupSubmenu).toHaveBeenCalled();
});
});


On Aug 27, 7:59 am, Davis Frank <dwfr...@pivotallabs.com> wrote:
> The "method does not exist" error, if the property is actually there, is
> most often due to spying later than when the method is added.
>
> Have you tried spying on popupSubmenu in your beforeEach?
>
> --dwf
>
Reply all
Reply to author
Forward
0 new messages