🧪 test
test(mensagem: string, cb: () => void)
|test(cb: () => void)
test
é um auxiliar para o ajudar em casos como:
- Usar
beforeEach
eafterEach
para cadatest
realizado - Isolar ou agrupar seus testes no mesmo arquivo
- Executar testes no mesmo arquivo em paralelo
Uso Básico
Isolando escopos
import { test, assert } from 'poku';
test(() => {
const minhaVar = 'a';
assert.strictEqual(minhaVar, 'a', 'Meu primeiro auxiliar de teste');
});
test(() => {
const minhaVar = 'b';
assert.strictEqual(minhaVar, 'b', 'Meu segundo auxiliar de teste');
});
Agrupando testes
import { test, assert } from 'poku';
test(() => {
assert.equal(1 + 1, 2, '1 + 1 deve ser 2');
assert.equal(2 + 2, 4, '2 + 2 deve ser 4');
});
import { test, assert } from 'poku';
test('Testes de soma', () => {
assert.equal(1 + 1, 2);
assert.equal(2 + 2, 4);
});
import { test, assert } from 'poku';
test('Testes de soma', () => {
assert.equal(1 + 1, 2, '1 + 1 deve ser 2');
assert.equal(2 + 2, 4, '2 + 2 deve ser 4');
});
Aguardando promessas
import { test } from 'poku';
await test(async () => {
// faça o que quiser
});
await test(async () => {
// faça o que quiser
});
Executando em paralelo
import { test } from 'poku';
test(async () => {
// faça o que quiser
});
test(async () => {
// faça o que quiser
});
Aguardando múltiplas promessas
import { test } from 'poku';
// faça algo antes
await Promise.all([
test(async () => {
// faça o que quiser
}),
test(async () => {
// faça o que quiser
}),
]);
// faça algo depois
dica
Você pode pensar nessa abordagem como beforeAll
e afterAll
.