Suppose there are two js files called main.js and test.js. main.js is the code that I intend to test it by Mocha and Chai. For that, I created test.js that includes expect()
function. expect()
is a Chai method and takes assessment the result we expect (Is the main function for testing code).
In main.js, There is a request method that I need to test it. The request method is a Promise and is a thenable function. As I read Chai doc, I should try expect()
inside the callback of .then()
, just like this:
chai.request(app)
.put('/user/me')
.send({ password: '123', confirmPassword: '123' })
.then(function (res) {
expect(res).to.have.status(200);
})
Hence, I should merge main.js to test.js. So, because of any modify on main.js, I must duplicate that change on test.js too. While, I need to include entire of main.js by require()
in test.js and test it there. So my question is:
How can I test a request method by expect()
in such a way that the request method remains in main.js and expect()
remains in the test.js, there is no need to try request method in the test.js (Like chai.request(app)
) and there is no need to try expect()
inside of the then()
callback (Like the mentioned code)?