why catch method is not invoked?

This issue has been tracked since 2019-03-26.

test('should fails with incorrect secret_key', (done) => {

        const errorResp = {
            status: 422,
            response: mock_objects.auth_inv_secret
        };
        conf.secret_key = 'aaabbb';
        let api = new ApiRequest(conf);
        api.Auth(); //call to backend 

        moxios.wait(function () {
            let request = moxios.requests.mostRecent();
            request.reject(errorResp);
        }).catch(error => {
            console.log(error);
            done();
        });
    });

Testing with jest i get -> TypeError: Cannot read property 'catch' of undefined

sstraatemans wrote this answer on 2019-09-02

bump

dbeff wrote this answer on 2019-10-10

I had the same issue @scrafy, did you find any solution for it?

scrafy wrote this answer on 2019-10-10
dbeff wrote this answer on 2019-11-08

The only way that I was able to make it works was:

moxios.wait(() => {
      const request = moxios.requests.mostRecent();
      request.respondWith({ status: 400 }).then(() => {
        try {
          // assert something
          done();
        } catch (err) {
          done.fail(err);
        }
      });
    });
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