Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

td.constructor() feature for creating fake constructors #54

Closed
searls opened this issue Nov 24, 2015 · 2 comments
Closed

td.constructor() feature for creating fake constructors #54

searls opened this issue Nov 24, 2015 · 2 comments

Comments

@searls
Copy link
Member

searls commented Nov 24, 2015

This is already basically implemented to support td.replace() (source) of constructors, but it's not exposed in an explicit way.

Given a constructor:

function Dog(){}
Dog.prototype.bark = function(){}
Dog.prototype.woof = function(){}

One could call (in environments supporting destructured assignment):

var [FakeDog, dog] = td.constructor(Dog)

Where FakeDog is a constructor that can be passed to the subject or otherwise replaced and dog is a plain JavaScript object of the same set of test doubles one would get if they instantiated new FakeDog().

One point of potential confusion for users is that instantiating FakeDog multiple times will yield the same set of fake functions, so the total number of stubbings & invocations would accumulate over all FakeDog instances, which would run counter to our expectations of statefulness with instantiated objects, but would be necessary for the test to have sane access to the test double functions. Feedback on this point would be welcome.

@searls searls added this to the Round out edge cases milestone Aug 12, 2016
@searls
Copy link
Member Author

searls commented Dec 13, 2016

Reminder in #164 that this should work on ES6 class static methods

@searls
Copy link
Member Author

searls commented Dec 14, 2016

Closing in favor of #166, in which case td.replace will give you exactly what td.constructor would have.

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

No branches or pull requests

1 participant