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

Provide mock implementations #5

Closed
jgornick opened this issue Dec 11, 2019 · 2 comments
Closed

Provide mock implementations #5

jgornick opened this issue Dec 11, 2019 · 2 comments

Comments

@jgornick
Copy link

Instead of having to modify mock implementations manually, it might be nice to allow an argument as the first argument in mock<...>({ ... }) which defines mock implementations/values for the instance:

interface ResourcesApi {
    get(id: string): Promise<any>
}

interface Api {
    resources: ResourcesApi
}

const api = mock<Api>({
  resources: {
    get: true // equivalent to api.resources.get.mockReturnValue(true)
    // or get: () => true which is equivalent to api.resources.get.mockImplementation(() => true)
  }
})

// instead of ...
// 

Refer to #3 for the nested support.

Thoughts?

@marchaos
Copy link
Owner

Hey.

Looks good. I now have this working. I have used DeepPartial so that you can provide incomplete implementations for the top level type and lower levels. Will create a PR shortly.

@marchaos
Copy link
Owner

Merged this change.

Beraliv pushed a commit to Beraliv/jest-mock-extended that referenced this issue May 1, 2024
* Run unit-test for PRs

* Run tests with coverage
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

No branches or pull requests

2 participants