Test passed even though it shouldn't be ?

This issue has been tracked since 2017-08-31.

Hi, I added an unit testing using moxios for our React application.
It seems that my test with moxios passes even though the test is a false condition.

Here is the code.

login-test.js

` . import React from 'react';
import Login from '../../src/components/Login';
import axios from 'axios';
import moxios from 'moxios';
describe('Login test', function () {
let data;

beforeEach(function () {
    data = { email: 'sample', password: 'sample' }
    moxios.install();
});

afterEach(function () {
    data = { email: 'sample', password: 'sample' }
    moxios.uninstall();
});

it('Send Login data', function (done) {

    axios.post('/login');

    moxios.wait(function () {
        const request = moxios.requests.mostRecent();
        request.respondWith({
            status: 200,
            response: { message: 'successfull', status: '200' },
        }).then(function () {
            equal(login.called, true)
        })
    });

    done()
  })
 })` 

// test passed

Here is the code with a false condition. I didn't assign a post router.

` . import React from 'react';
import Login from '../../src/components/Login';
import axios from 'axios';
import moxios from 'moxios';
describe('Login test', function () {

  let data; 

beforeEach(function () {
    data = { email: 'sample', password: 'sample' }
    moxios.install();
});

afterEach(function () {
    data = { email: 'sample', password: 'sample' }
    moxios.uninstall();
});

it('Send Login data', function (done) {

    **axios.post('/');**

    moxios.wait(function () {
        const request = moxios.requests.mostRecent();
        request.respondWith({
            status: 200,
            response: { message: 'successfull', status: '200' },
        }).then(function () {
            equal(login.called, true)
        })
    });

    done()
})
})`

This test passed. I tried testings with several conditions and the tests passed in most cases.

HavokInspiration wrote this answer on 2017-11-21

I had the same problem and stumbled upon your issue while browsing the web.

If it can be of any help, I managed to solve my issue and see you are more or less having the same thing as I did : your done() call should be in the callback you pass to the moxios.wait() method.

I hope this will help you.

anilanar wrote this answer on 2018-05-27

Kamino cloned this issue to anilanar/moxios

MadeoIT wrote this answer on 2018-08-15

If done() is in your callback the test silently fail with:
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Without any feedback whatsoever, which is understandable somehow.
If you catch the error to have some feedback, then the test pass even though it actually failed...
Am I doing something wrong or it really that cumbersome ?

More Details About Repo
Owner Name axios
Repo Name moxios
Full Name axios/moxios
Language JavaScript
Created Date 2016-05-25
Updated Date 2022-12-05
Star Count 1386
Watcher Count 20
Fork Count 85
Issue Count 19

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date