Skip to content

Instantly share code, notes, and snippets.

@falexandre
Last active March 7, 2018 10:22
Show Gist options
  • Save falexandre/dcd53371e8445dc5b3fdd0c74f9a2378 to your computer and use it in GitHub Desktop.
Save falexandre/dcd53371e8445dc5b3fdd0c74f9a2378 to your computer and use it in GitHub Desktop.
Test com Mocha and Chai
> npm i -D mocha chai
> package.js
"test" : "./node_modules/.bin/mocha/ {PASTA_TESTES}/**/*.spec.js -b -R strip"
mocha -b -r babel-polyfill -r babel-core/register -R landing tests/**/**.spec.js
https://mochajs.org/#usage
-b para no primeiro erro que acontecer
-R tipo aviazinho progress
#### DICAS #####
context.only or describe.only somente irá rodar aquele teste
it.skip ignora aquele teste, exemplo sei que ele esta quebrando mas quero corrigir depois
Hooks ajudam eventos para mooks etc
https://mochajs.org/#hooks
Chai é para testar de fato http://chaijs.com/api/bdd/
#### FIM DICAS ####
#### EXEMPLO ######
describe("Main" function() {
describe("Method A" function() {
context("Caso 1" function() {
// Deveria fazer
it("schold happen ..." function() {
//aqui é o que esperamos que aconteça de fato o teste
// testa o que entra de dados
// testa o que esperamos retornar
})
})
context("Caso 2" function() {
})
})
describe("Method B" function() {
context("Caso 1" function() {
})
context("Caso 2" function() {
})
})
})
#### FM EXEMPLO ######
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment