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

typings: make MockFunction generic #267

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Conversation

uwinkelvos
Copy link
Contributor

this allows esmock to be used in a more convenient way in typescript setups

import esmock from 'esmock';
import type * as moduleUnderTest from './moduleUnderTest.js';

const { func } = await esmock<typeof moduleUnderTest>(
  './moduleUnderTest.js',
  import.meta.url,
  {
    //...
  },
);
const actual = await func();

this allows esmock to be used in a more convenient way in typescript setups

```
import esmock from 'esmock';
import type * as moduleUnderTest from './moduleUnderTest.js';

const { func } = await esmock<typeof moduleUnderTest>(
  './moduleUnderTest.js',
  import.meta.url,
  {
    //...
  },
);
const actual = await func();
```
@uwinkelvos
Copy link
Contributor Author

Btw thank you so much for creating this module @bumblehead! :)

src/esmock.d.ts Outdated
@@ -22,19 +22,19 @@ type MockFunction = {
* @param opts
* @returns The mocked import-tree result of "import({@link modulePath})"
*/
(
<T>(
Copy link
Collaborator

@koshic koshic Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<T = any>, to keep 'any' type by default. Without '= any', esmock(...) result will be Promise<unknown>

@uwinkelvos uwinkelvos requested a review from koshic November 7, 2023 15:48
@koshic koshic merged commit b88ab9c into iambumblehead:main Nov 7, 2023
10 checks passed
@iambumblehead
Copy link
Owner

@uwinkelvos thanks for the thanks --that makes me glad to read that.

Its fine for me if @koshic publishes, but I'm going to publish now since it is not published. one moment...

@koshic
Copy link
Collaborator

koshic commented Nov 7, 2023

@iambumblehead just want you do decide - it's not an emergency case, so )

@iambumblehead
Copy link
Owner

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.

4 participants