CreateSpyObj on property function

1,289 views
Skip to first unread message

Michael Andersson

unread,
Oct 23, 2015, 1:05:53 PM10/23/15
to Jasmine
Given that I have a dependency that has the 3 public methods I.E.

dependency
--method1()
--method2()
--method3()

I could easily use createSpyObj like so:
var someMock = jamine.createObjSpy('someMock',['method1','method2', 'medthod3']);

But what if the dependency exposes a property that exposes a method I.E.
dependency
--method1()
--method2()
--method3()
--property1.method()

I am unsure of what route to take here.

Gregg Van Hove

unread,
Oct 23, 2015, 7:38:22 PM10/23/15
to jasmi...@googlegroups.com
The object returned by `createSpyObj` is just a plain javascript object, with properties that are spies for anything you pass to it. This means you should be able to set `property1` on the result. Something like this would probably work:

var someMock = jasmine.createSpyObj('someMock',['method1','method2', 'medthod3']);
someMock.property1 = jasmine.createSpyObj('property1', ['method']);

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages