H
H
HoHsi2016-03-10 15:35:59
JavaScript
HoHsi, 2016-03-10 15:35:59

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

If the cycle is pushed into the body, then the test will take a very long time. And it won’t work to shut up with a mock, because work with the base is partly tested.
In this case, how would it be more beautiful to rewrite this code, given that there is almost 90% repeatable test only without plugins, to check how REST behaves without parameters passed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question