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

introduce td.constructor() as top-level API sibling to td.object() & td.function() #201

Merged
merged 6 commits into from
Mar 10, 2017

Conversation

searls
Copy link
Member

@searls searls commented Mar 10, 2017

Fortunately 2.0.0 is in preview, because I just realized this morning how horrible of an impedance mismatch I've created by having td.object() accept constructor functions and returning fake constructors.

How it used to work

This is how we got here

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

var fakeDog = td.object(Dog) // a function bag

fakeDog.bark // <-- a test double function.

td.object() would return a function bag by inspecting the constructor you pass it.

That changed!

And now in 2.0 when you pass a constructor to td.object, you get a fake constructor with test double functions on the prototype.

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

var FakeDog = td.object(Dog) //<-- a constructor

FakeDog.prototype.bark // <-- a test double function.

Changes in this PR:

  • you can no longer pass a constructor function to td.object
  • new API that is td.constructor that takes a real constructor and returns a fake constructor
  • accept similar input to td.object (namely, an array of function names creates a fake constructor from nothing) td.constructor(['bark'])
  • improve the toString impl for fake instances
  • fix a bunch of tests
  • add name to td.explain
  • add error to td.object
  • fix the repl
  • update docs for td.object
  • add doc for td.constructor (namely that you can pass a constructor or an array of names
  • update doc for td.explain

* add td.constructor(['a','b'])
* fix examples
* log when td.object is passed a constructor
* add name to td.explain
@searls searls merged commit 713ea76 into master Mar 10, 2017
@searls searls deleted the refactor-creation branch March 10, 2017 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant