-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
In strongloop-archive/loopback4-example-getting-started#2, the proposed acceptance tests are relying on the first test to fill the database with data that's used by subsequent tests:
it('creates a todo', async () => {
item = (await client
.post('/todo')
.send(payload)
.expect(
Object.assign({}, payload, {
id: 1
})
)).body;
});
//...
it('successfully deletes todos', async () => {
await client.del(`/todo/${item.id}`).send();
await client
.get(`/todo/${item.id}`)
.send()
.expect(404);
});(see strongloop-archive/loopback4-example-getting-started#2 (comment))
This is an anti-pattern to avoid:
- if the first test fails, all subsequent tests fail too (because data was not filled in), but with an unhelpful error message is confusing.
- it is not possible to run individual tests on their own, e.g. via
it.only()ormocha -g "test name".
We should extend Data Handling in Testing your Application to mention this pattern and explain why it's a bad thing to do.
Reactions are currently unavailable