We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I got code like this
method.js
export function deleteImageFromServer(id){ return axios.post('http://localhost:8000/'+'delete', {id:id}) }
home.spec.js
import {deleteImageFromServer} from './method' import MockAdapter from 'axios-mock-adapter' import axios from 'axios' import {expect} from 'chai' describe('deleteImageFromServer', function () { it('should delete image', function () { let mock = new MockAdapter(axios) mock.onPost('http://localhost:8000/delete').reply(function(){ return [200, 'success'] }) deleteImageFromServer(1).then( (r) =>{ expect(r.data).to.equal('success') }) }) })
I don't know why the intercept never happens.
The text was updated successfully, but these errors were encountered:
You're doing some asynchronous stuff, but you're not waiting for it to finish. If you're using Mocha, you can return a promise:
import {deleteImageFromServer} from './method' import MockAdapter from 'axios-mock-adapter' import axios from 'axios' describe('deleteImageFromServer', function () { it('should delete image', function () { let mock = new MockAdapter(axios) mock.onPost('http://localhost:8000/delete').reply(function(){ return [200, 'success'] }) return deleteImageFromServer(1).then( (r) =>{ expect(r.data).to.equal('success') }) }) })
Sorry, something went wrong.
@ctimmerm thanks, that works, but I don't know why would the 'return' keyword means waiting in this case, can you explain more?
waiting
It's Mocha feature: https://mochajs.org/#working-with-promises. When you return a promise, Mocha can wait for the promise to resolve.
No branches or pull requests
I got code like this
method.js
home.spec.js
I don't know why the intercept never happens.
The text was updated successfully, but these errors were encountered: