Add instance mocks #37

Closed
jamesarosen opened this Issue Dec 15, 2010 · 1 comment

Comments

Projects
None yet
2 participants
@jamesarosen

I'd like to be able to mock out an object created via new. Perhaps something like

mockClass('Image');
var i = new Image();
i.src = '/some_url';
expect(Image.lastInstance().src).toEqual("/some_url");

or maybe

mockClass(Vehicle, 'Car');
var c = new Vehicle.Car();
c.start();
expect(Vehicle.Car.anyInstance().start).toHaveBeenCalled();

I might also imagine being able to access the original definition of the "class" (function) via StubbedFunction.originalDefinition.

@infews

This comment has been minimized.

Show comment Hide comment
@infews

infews Jan 28, 2011

Contributor

Your latter example can be done with jasmine.createSpyObj - you can create an Object with a bunch of spies as functional properties. We do this a lot in our testing.

Your "instance" interface looks interesting. Why not test-drive the concept and see if you can get some traction?

Contributor

infews commented Jan 28, 2011

Your latter example can be done with jasmine.createSpyObj - you can create an Object with a bunch of spies as functional properties. We do this a lot in our testing.

Your "instance" interface looks interesting. Why not test-drive the concept and see if you can get some traction?

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment