Moxios is a request mocking framework for axios, JavaScript HTTP client.
Questions tagged [moxios]
46 questions
2
votes
2 answers
Unable to get Moxios stubRequest to work
I'm having issues getting stubRequest to work properly. Here's my code:
it('should stub my request', (done) => {
moxios.stubRequest('/authenticate', {
status: 200
})
//here a call to /authenticate is being made
…

Rinux
- 815
- 1
- 9
- 18
2
votes
0 answers
Unable to trigger request on a subcomponent
I'm trying to add a test that could check a request sent from within vue-upload-component.
The request is sent when "Upload Files" button is clicked, the problem is that it's not triggered when I simulate it.
Normally I would do it like this (using…

van_folmert
- 4,257
- 10
- 44
- 89
2
votes
0 answers
Testing axios post in nested redux dispatch
I have an redux action someFunc that dispatches 4 actions including an axios post, this dispatch is called within another dispatch called someOtherFunc.
I am mocking the axios post with moxios and redux-mock-store to test the correct actions are…

frage
- 719
- 7
- 15
1
vote
1 answer
Mock api call using moxios
I am not very familier yet on how to write unit tests via moxios and your help would be very much appreciated.
My request is the following:
export const walletRequest = () => {
return AWAxiosInstance()
…

Anca
- 21
- 4
1
vote
1 answer
Code coverage not working for Jest test with Axios
I am using Jest and moxios to write a test for my async function:
export function getData(id) {
return dispatch => {
return axios({
method: "get",
url: `${'url'}/id`
})
.then(response => {
…

darKnight
- 5,651
- 13
- 47
- 87
1
vote
1 answer
Testing concurrent requests in redux-thunk with Jest and Moxios
I am having trouble testing a function with concurrent API calls. Here's the code I want to test that relies on redux-thunk :
const loadResources = () => {
return (dispatch) => {
dispatch(setLoaderState(true))
// events
…

David Geismar
- 3,152
- 6
- 41
- 80
1
vote
1 answer
integration test for axios fetching, and it fails when I apply the `done` as callback in the `it` function with jest
I am trying to run a Jest test for a network fetching in my integration test. It used beforeEach to create a fake network fetching response, and it should return a response of length 2. The test goes well when I remove the done from the following…

DSL
- 31
- 4
1
vote
1 answer
catch is not invoked on moxios reject
I am trying to test the rejection of one of my axios request call using moxios and jest. The method invoke (calling axios.get) throws error but catch block is not invoked.
My test code snippet is shown below,
it('should call errorHandler method when…

Sabu Shakya
- 334
- 4
- 15
1
vote
1 answer
Mock an external endpoint in NodeJs by Moxios
I am trying to mock an external endpoint of Twilio in the unit test by Moxios library. I am also using SuperTest library to provide the exceptions of the test.
My internal endpoint which is called by Front-end is:
router.get('/twilio', async (req,…

peyman gilmour
- 1,168
- 2
- 16
- 35
1
vote
2 answers
Moxios Stubrequest with Regular Expression
I have tried to use a moxios Stubrequest with a regex like comments/.*/vote but it is not working. The .* is populated with identifiers (integer). Any idea how to make this work? Thanks
Code
moxios.stubRequest('/comments/.*/vote', {
status:…

Adrian Hernandez-Lopez
- 553
- 4
- 18
1
vote
1 answer
how to test async function making use of moxios?
Consider the following react code.
sendFormData = async formData => {
try {
const image = await axios.post("/api/image-upload", formData);
this.props.onFileNameChange(image.data);
this.setState({
uploading: false
…

Unity Hour
- 550
- 2
- 7
- 22
1
vote
1 answer
Moxios Requests State Not Cleared In Between Tests
My specs are behaving weirdly in that when I run the tests alone, they pass. However, when I run the test suite all together, the failure tests still continue to use the success axios mock instead of using the correct failing http axios mock. This…

PressingOnAlways
- 11,948
- 6
- 32
- 59
1
vote
1 answer
Jest asynchronous tests notify test finished with a failure
I have following test cases, both are passing when I expected the test to be marked as failing:
// testing.test.js
describe('test sandbox', () => {
it('asynchronous test failure', done => {
Promise.resolve()
.then(_ => {
//…

Lukasz 'Severiaan' Grela
- 6,078
- 7
- 43
- 79
1
vote
1 answer
Avoid vue warnings when mocking router in vue.js tests
I'm testing a Vue.js 2 application which uses Axios for HTTP requests and I am mocking these requests with Moxios. The test uses Avoriaz as well.
The page I am testing just renders a list of elements and displays some buttons which are implemented…

GreenTurtle
- 1,144
- 2
- 21
- 35
1
vote
0 answers
Testing Redux async action creator does not call .then()
I am trying to test a Redux action creator and am not able to get the .then of the returned promise to execute. I am using Moxios to mock my HTTP requests which are coming from Axios. Here is the Moxios setup:
import moxios from "moxios"
import…

Arun
- 626
- 10
- 29