Answer the question
In order to leave comments, you need to log in
What is the best way to test a complex site?
Good afternoon!
I came across this question: how will it be more correct and beautiful to test plugins in mocha.js?
Now I just generate tests through the forEach loop and run them, but it seems to me that this is not the most beautiful option:
[30, 18, 378, -9000].forEach(function (userLimit) {
it(`should response valid chunked (limit: ${userLimit}) data `, async function () {
const agent = request.agent(app);
await agent
.post('/rest/auth')
.send({
username,
password
});
let users = [];
let offset = 0;
while (offset <= totalUserCount) {
await agent
.get('/rest/users')
.query({
limit: userLimit,
offset: offset
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
const {body} = res;
users = users.concat(body.data);
if (userLimit < 1) {
offset += 1;
} else if (userLimit > 100) {
offset += 100;
} else {
offset += userLimit;
}
});
}
expect(users).have.lengthOf(totalUserCount);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question