Skip to content

Support for mocking new instances #1

@has207

Description

@has207

I didn't see this mentioned in the docs so I've worked around it for now, but it would nice for jsmocha to support it natively. The workaround:

var saved = foo.bar.Constructor;
var Temp = function() {};
foo.bar.Constructor.prototype = new Temp();
foo.bar.Constructor.prototype.expects('someMethod');
// call the code
foo.bar.Constructor = saved;

The painful part is the save/restore, though it shouldn't really be all that necessary to create the Temp constructor either.

Maybe something like:

mock_object = {};
foo.bar.Constructor.new_instances(mock_object);
mock_object.expects('someMethod');
// call the code

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions