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

Create mock for kolibri.resources that automocks every exported Resource class #8082

Merged
merged 4 commits into from
May 13, 2021

Conversation

jonboiser
Copy link
Contributor

This simplifies the mocking of kolibri.resources. Now, if your test might call some resource, do this:

jest.mock('kolibri.resources')

This will import a mock that automocks every Resource class. Then, if you need to mock a specific Resource, import it, set its mock behavior (and remember to reset it at the end of the test)

import { FacilityUserResource } from 'kolibri.resources';

jest.mock('kolibri.resources')

describe('', () => {
  afterEach(() => {
    FacilityUserResource.fetchCollection.mockReset();
   })
  it('...', () => {
	FacilityUserResource.fetchCollection.mockResolvedValue([...]);
   })
})

Since this mock should handle most use cases, I also deleted the jestMockResource utility.

@jonboiser jonboiser added the TAG: dev experience Build performance, linting, debugging... label May 12, 2021
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Nice, good cleanup! Tests still pass, so looking good.

@rtibbles rtibbles merged commit 8f8eb3d into learningequality:develop May 13, 2021
@jonboiser jonboiser deleted the new-resource-mock branch May 13, 2021 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TAG: dev experience Build performance, linting, debugging...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants