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

Align TS replace() signuatrue return with implementaiton #173

Merged
merged 1 commit into from
Dec 30, 2016

Conversation

danielmoore
Copy link

@danielmoore danielmoore commented Dec 30, 2016

This PR changes the TypeScript type definition for td.replace() to return any instead of void.

Per the documentation:

td.replace(object, propertyName, [manualReplacement])

[...]
td.replace typically returns the fake thing it sets on object, with the
exception of constructor function properties. In that case, it will return a
plain object of test double functions to the test, but set object[propertyName]
to a constructor function that delegates to those test double functions only
after it's been instantiated with new.

and

td.replace(relativePathToModule, [manualReplacement])

[...]
Once defined, it will return a fake thing based on the same
inferences discussed above and replace subsequent calls to require for that
module until the next call to td.reset()


For any downstream users who need these changes sooner, you can add a file to your code named something like testdouble-overrides.d.ts with the following content:

import 'testdouble';

declare module 'testdouble' {
  export function replace(path: string, f?: any): any;
  export function replace(path: {}, property: string, f?: any): any;
}

@searls
Copy link
Member

searls commented Dec 30, 2016

I'll have to take your word for it but it seems legit

@searls searls merged commit 46a8fba into testdouble:master Dec 30, 2016
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

2 participants