mardi 30 juillet 2019

The test does not wait for the input number

I am testing phone number verification.

import { expect } from 'chai';
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from '../../src/index';
import readline from 'readline';

chai.use(chaiHttp);

const setEntryId = utils.getentryIds();
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

describe(`Verification Phone Of Users Test`, () => {
    describe('POST /api/users/verifyp', () => {
        it(`Should pass verification users`, (done) => {
            rl.question('You must enter the code from the SMS:', (code) => {
                chai
                    .request(server)
                    .post('/api/users/verifyp')
                    .send({ 'code': code })
                    .end((err, res) => {
                         expect(res).have.status(200);
                         expect(res.body).have.property('message');
                         expect(res.body.message).to.be.an('string');
                         done();
                     });
                 rl.close();
             });
         });
     });
});

Test run script.

SET NODE_ENV=test && mocha -exit --timeout 10000 --require @babel/registe

The problem is that I get an error.

Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

How can I make the test wait until I enter the number?

I understand that I have a time out, but I increased it and he also gave an error.

Aucun commentaire:

Enregistrer un commentaire