Moxios is a request mocking framework for axios, JavaScript HTTP client.
Questions tagged [moxios]
46 questions
1
vote
1 answer
Testing API call in Vue with Moxios
I am having trouble figuring out how to test an API call that happens in the "mounted" lifecycle hook.
I have a single file component that is responsible for displaying some information about an "Owner".
This works exactly how I want / expect in…

Trinculo
- 1,950
- 1
- 17
- 22
0
votes
1 answer
How to test setState after getting response from an api
I am doing unit testing using jest and enzyme on my reactjs code,where I have main functional component "TrashDisplayFiles" inside which there is a method "getDeletedData",where I have called the api which is setting TrashFileState by getting…

Vanshika
- 11
- 2
0
votes
1 answer
Jest Enzyme Test Case mock API with Moxios not working
Here is the Component Code where i call API with getAllData method and set data to the state:
class MyComponent extends Component {
state = {
allStatus: []
}
componentDidMount() {
this.getAllData();
}
getAllData = async() => {
let res =…

Tarun Kumar
- 140
- 1
- 1
- 9
0
votes
1 answer
I want to test react API with moxios
I am learning testing with jest and enzyme. I want to test an API with moxios but facing a lot of challenges. I have an API call as below:
useEffect(() => {axios.get(`https://API/call/with/dynamicvalue/${id}`,
{
headers: {
…

Shayane
- 33
- 2
- 9
0
votes
1 answer
How do you use both moxios and supertest's request on an endpoint that has 2 axios requests one that needs to be stubbed and one that shouldn't?
Say I've got an expressjs app, app, setup and an endpoint like so:
app.get('/endpoint', endPointFunction)
The function is setup like this:
const axios = require('axios');
var endpointFunction = async(req, res) =>{
try{
const a = await…

Kerfuffle
- 11
- 1
0
votes
1 answer
Correct usage of moxios
I'm trying to mock an axios request in a function using moxios. Test is running fine and getting the expected result, but I don't think they way I implemented it is not a best practice at all. Could someone please suggest me a better way to achieve…

Remil Michael
- 41
- 2
- 9
0
votes
1 answer
moxios not working properly when using window.axios
I have a laravel project. I am trying to test a vue component and it was showing errors:
This is my test: test.spec.js
import { mount } from '@vue/test-utils';
import expect from 'expect';
import moxios from 'moxios';
import Post from…

Luis
- 325
- 4
- 20
0
votes
1 answer
Moxios always retuning empty when using thunk and axios
I'm stuck trying to mock my axios function which is always returning empty:
LoginAction:
export function loginUser(email, password) {
return function(dispatch) {
return axios
.post(`${API_URL}/users/authenticate`, { email, password }, {…

lost9123193
- 10,460
- 26
- 73
- 113
0
votes
1 answer
How to intercept two axios requests in the same test using moxios
I am trying to test a delete button in my app. When the app initialises it makes an axios request to the server to get a list of benefits. When the delete button is clicked another request is made. For some reason my test just won't intercept the…

user5036826
- 60
- 5
0
votes
1 answer
How to fix moxios test failing with axiosInstance.get('url').then(...).finally is not a function
Hi I am trying to write a simple test case with help of moxios
I have the project setup in my multiple systems(pc) and the code is in sync with git. The problem is that test is failing for one system only. It is working in all pc except one.
I have…

innovativesahil
- 37
- 1
- 5
0
votes
1 answer
How can I do a jest test in this function in React axios?
I guys I created a service in React and I need to test this part of the service, I'm using axios and Jest to do this.
I have the next code in React :
import axios from 'axios';
import Endpoints from './endpoints';
const baseUrl =…

Angel Mora
- 5
- 1
0
votes
0 answers
How to fix "Network Error" testing a react/redux app with moxios
I am working on a new project that consist on a backend API and a react/redux frontend app. I am setting up my first test using jest/enzyme/moxios.
My issue is that, when the api server is not running the test returns "Network error", but all test…

David
- 519
- 2
- 11
0
votes
1 answer
Jest How to test error while submitting data to server from form?
Consider the following code :
class Dashboard extends Component {
state = {
fileName: "",
group: "",
country: "",
error: ""
};
onFormSubmit = async e => {
e.preventDefault();
const { group, country } = e.target;
try…

Unity Hour
- 550
- 2
- 7
- 22
0
votes
1 answer
err in a redux action test
I'm new to Jest testing and moxios. Just trying to write my first async action test. Test dies with this error:
Expected value to equal:
[{"payload": {"checked": true, "followingInfoId": "1"}, "type": "HANDLE_FAVORITE_SUCCESS"}]
Received:
…

Andrew Korin
- 294
- 3
- 17
0
votes
1 answer
Vuejs testing value after click
Something wrong here

MartinM
- 1,736
- 5
- 20
- 33