testing the new constructor

723 views
Skip to first unread message

mwillhite

unread,
Aug 16, 2011, 12:39:52 PM8/16/11
to Jasmine
This may just be a huge oversight due to my lack of experience, but I
can't seem to find a good way to test that an object was instantiated.

Say I have the following:

var blah = function() {
new google.maps.LatLng(123, 456);
}

How can I ensure that the google.maps.LatLng object was instantiated
(or constructed?) ?

Thanks!

Aaron McLeod

unread,
Aug 17, 2011, 1:42:56 PM8/17/11
to jasmi...@googlegroups.com
I think you would just stub it out like any other function:

spyOn(google.maps, 'LatLng');

Note that in your spec file, google.maps must have the LatLng function defined as part of its structure, or else youll get an undefined function error.


--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.




--
Aaron McLeod
http://agmprojects.com

Peter Jaros

unread,
Aug 17, 2011, 3:42:12 PM8/17/11
to jasmi...@googlegroups.com
On Wed, Aug 17, 2011 at 1:42 PM, Aaron McLeod <sircoo...@gmail.com> wrote:
> I think you would just stub it out like any other function:
> spyOn(google.maps, 'LatLng');

You can even demonstrate that it was returned:

var blah = function() {
return new google.maps.LatLng(123, 456);
}

var latLng = {};
spyOn(google.maps, 'LatLng').andReturn(latLng);
expect(blah()).toBe(latLng);

Peter

mwillhite

unread,
Aug 18, 2011, 1:21:04 PM8/18/11
to Jasmine
Cool thanks

On Aug 17, 12:42 pm, Peter Jaros <pja...@pivotallabs.com> wrote:
> On Wed, Aug 17, 2011 at 1:42 PM, Aaron McLeod <sircoolgu...@gmail.com> wrote:
> > I think you would just stub it out like any other function:
> > spyOn(google.maps, 'LatLng');
>
> You can even demonstrate that it was returned:
>
> var blah = function() {
>   returnnewgoogle.maps.LatLng(123, 456);
Reply all
Reply to author
Forward
0 new messages