Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

Mobx tests #17

Merged
merged 19 commits into from
Feb 4, 2020
Merged

Mobx tests #17

merged 19 commits into from
Feb 4, 2020

Conversation

@codeBelt codeBelt requested a review from ccheney February 2, 2020 14:46
@codeBelt codeBelt added the help wanted Extra attention is needed label Feb 2, 2020
.get('/search/shows?q=Friends')
.reply(200, {
results: 'any thing so that I can see this fail at least',
});
Copy link
Owner Author

@codeBelt codeBelt Feb 2, 2020

Choose a reason for hiding this comment

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

@n8rzz I need help. I can't get nock to work.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Maybe none of the axios request are being made within jest? If I remove nock and check if the request was actually made I don't get anything even if I add a try/catch within requestAction. No code gets called after the await. https://github.com/codeBelt/nextjs-mobx/blob/master/src/utilities/mobxUtil.ts#L19

Copy link

Choose a reason for hiding this comment

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

how does async work with mobx here? .serach() isn't listed as async, however it does end up calling ._requestData() which is. perhaps that's causing issues.

everything else checks out. your tests are passing (for me at least) and everything seems to be working ok, minus the async item above. One other thing to call out, nock only nocks one time. So you may want to abstract anything nock related into a function that runs the nock stuff and can be easily repeated.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think nock is working. I update this test with how I would like it to fully work. Notice the before and after comments. nock is not returning the expectedData. What I am getting is an HttpErrorResponseModel and don't know why when nock should be catching the request

Copy link
Owner Author

@codeBelt codeBelt Feb 3, 2020

Choose a reason for hiding this comment

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

This fixed my issue: axios/axios#1754 (comment)

Need to change the jest environment:
https://jestjs.io/docs/en/configuration.html#testenvironment-string

/**
 * @jest-environment node
 */

@@ -0,0 +1,31 @@
export const SearchLocalStoreMockData = [
Copy link
Owner Author

Choose a reason for hiding this comment

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

@n8rzz where should I put mock data files?

Copy link

Choose a reason for hiding this comment

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

For mocks shared by more than one domain, I prefer a root dir called __mock__. I'll also put a __fixtures__ dir at the root as well so that each is easily accessible by other tests that may need them. For domain-specific mocks, I like another __mocks__ dir near the domain (like stores, etc).

There very likely are cases where root a __mocks__ dir doesn't make sense, but frequently you will have an entity used in multiple domains across an application. Think of a Project model that would be needed for tests within the stores, but also tests with components (src/stores and src/components).

@codeBelt codeBelt merged commit 066b26d into master Feb 4, 2020
@codeBelt codeBelt deleted the mobx-tests branch February 4, 2020 13:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants