Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting error : Resolution method is overspecified. Specify a callback *or* return a Promise; not both

when i run my function it gives me error : Resolution method is overspecified. Specify a callback *or* return a Promise; not both. can anyone please check my code, and help to resolve this issue ? here i have placed my full code

it('Get Organizations', async function (done) {
        let user_permission = await commonService.getuserPermission(logged_in_user_id,'organizations','findAll');
        let api_status = 404;
        if(user_permission) { 
            api_status = 200;
        }

        let current_token = currentResponse['token'];
        old_unique_token = current_token;

        chai.request(app)
            .post('entities')
            .set('Content-Type', 'application/json')
            .set('vrc-access-token', current_token)
            .send({ "key": "organizations", "operation": "findAll" })
            .end(function (err, res) {
                currentResponse = res.body;
                expect(err).to.be.null;
                expect(res).to.have.status(api_status);
                done();
            }); 

    });
like image 442
taks Avatar asked Oct 27 '25 08:10

taks


1 Answers

Don't use done when defining an async unit test function, rather simply return as you normally would from an async method, after awaiting the request from chai-http:

it('Get Organizations', async function () {
        let user_permission = await commonService.getuserPermission(logged_in_user_id,'organizations','findAll');
        let api_status = 404;
        if(user_permission) { 
            api_status = 200;
        }

        let current_token = currentResponse['token'];
        old_unique_token = current_token;

        await chai.request(app) // note 'await' here
            .post('entities')
            .set('Content-Type', 'application/json')
            .set('vrc-access-token', current_token)
            .send({ "key": "organizations", "operation": "findAll" })
            .then(function (err, res) { // not 'then', not 'end'
                currentResponse = res.body;
                expect(err).to.be.null;
                expect(res).to.have.status(api_status);
            }); 

    });

The test runner will await your function automatically.

like image 50
Myk Willis Avatar answered Oct 28 '25 23:10

Myk Willis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!