Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在mocha和chai中处理异步测试?_Javascript_Mocha.js - Fatal编程技术网

Javascript 如何在mocha和chai中处理异步测试?

Javascript 如何在mocha和chai中处理异步测试?,javascript,mocha.js,Javascript,Mocha.js,我需要按顺序运行一系列测试。所有测试都是异步的,并且依赖于前一个测试。我在处理测试的异步方面遇到了很多麻烦 我试着用摩卡咖啡的步骤,但没用 步骤不是一个函数 我还尝试将descripe块嵌套在另一个descripe块中的before()hook中。在这种情况下,我将进行mongoose查询,并将在另一个变量中接收到的数据赋值,而赋值不会发生。我以为before()块应该处理这个问题 var token describe("Email confirmation", function () {

我需要按顺序运行一系列测试。所有测试都是异步的,并且依赖于前一个测试。我在处理测试的异步方面遇到了很多麻烦

我试着用摩卡咖啡的步骤,但没用

步骤不是一个函数

我还尝试将descripe块嵌套在另一个descripe块中的
before()
hook中。在这种情况下,我将进行mongoose查询,并将在另一个变量中接收到的数据赋值,而赋值不会发生。我以为
before()
块应该处理这个问题

var token
describe("Email confirmation", function () {

        before(function () {
            describe("Signup test", function () {
                it("Should register user and sends an email confiramtion token to registred email Id", function (done) {
                    agent
                        .post('/register')
                        .send({
                            unique_username: "xyz",
                            email: "xyz@gmail.com",
                            password: "12345"

                        })
                        .end(function (err, res) {
                            res.should.have.property('status', 200);
                            expect(res.body).to.contain.property('type')
                            expect(res.body).to.contain.property('msg')
                            // expect(res.body).to.deep.equal({});

                            done();
                        })
                })
            })

            User.findOne({ email: "xyz@gmail.com" }, function (err, data) {

                Token.findOne({ _userId: data._id }, function (err, data1) {

                    token = data1.token

                })

            })
        })


        it("Should verify the email Id of a registered user", function (done) {

            agent
                .post('/email_confirmation')
                .send({
                    email: "xyz@gmail.com.com",
                    token: token
                })
                .end(function (err, res) {
                    res.should.have.property('status', 200);
                    expect(res.body).to.contain.property('type')
                    expect(res.body).to.contain.property('msg')

                    done();
                })
        }).timeout(10000)
    })

希望先执行before()即“注册测试”块,然后执行另一个descripe块。

传递async或在before中完成?@Estradiaz不使用async或不可能重复的