-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add testing example to README #309
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but I'm thinking it might be a little better to combine the two code blocks into one example and using a diff to show the incorrect versus correct implementation. You can use a codeblock marked diff
like so:
import apisauce from 'apisauce'
import MockAdapter from 'axios-mock-adapter'
test('mock adapter', async () => {
const api = apisauce.create("https://api.github.com")
- const mock = new MockAdapter(axios)
+ const mock = new MockAdapter(api.axiosInstance)
mock.onGet("/repos/skellock/apisauce/commits").reply(200, {
commits: [{ id: 1, sha: "aef849923444" }],
});
const response = await api..get('/repos/skellock/apisauce/commits')
expect(response.data[0].sha).toEqual"aef849923444")
})
Overall I think it would read clearer and has the benefit of clearly indicating the incorrect implementation in red and the correct one in green.
Good idea, @kevinvangelder |
Yea, good suggestion @kevinvangelder. I've pushed that update. I wish we could do syntax highlighting with diff, but it is easier to follow with the diff 👍 |
Thanks for the contribution @theSteveMitchell !! Really appreciate it! |
🎉 This PR is included in version 3.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
#50 was helpful for me to understand an unexpected issue with testing. Hopefully it'll be helpful to others who have similar issues.
In my case, we are using axois-mock-adapter for mocking api requests. I think this is an extremely common package and pattern. We upgraded apisauce from 1.21.2 to 1.21.4, and all of the mocks stopped working.
@skellock's comment helped us to identify the issue, and when we looked through the code we found that 1.21.3 clones the axios instance which was not happening in 1.21.2. I wasn't able to find anything in release notes about that, and we didn't expect this to change in a minor/patch release