0

I have a series of tests i need to run in a sequential order. All the tests are asynchronous and dependent on the previous one. I am having a lot of trouble in handling the asynchronous aspect of the test.

I tried using mocha-steps, didn't work.

step is not a function

I also tried nesting a describe block inside a before() hook inside another describe block. In this situation i am making a mongoose query and assigning the data received inside another variable, where the assignment is not happening. I thought the before() block was supposed to handle this?

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)
    })

Expect the before() that is "Signup test" block to execute first and then the other describe block.

0 Answers0