goldbergyoni / goldbergyoni/javascript-testing-best-practices
Use Mocha's context (alias for describe)
- Dominant language
- JavaScript
- Stars
- 24.6k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
I like Mocha's `context` alias for `describe`. Consider the following example (from 1.1):
```JS
//1. unit under test
describe('Products Service', function() {
describe('Add new product', function() {
//2. scenario and 3. expectation
it('When no price is specified, then the product status is pending approval', ()=> {
const newProduct = new ProductService().add(...);
expect(newProduct.status).to.equal('pendingApproval');
});
});
});
```
It could be rewritten:
``` JS
//1. unit under test
describe('Products Service', () => {
// 2. specific capability
describe('Add new product',() => {
// 3. scenario
context('When no price is specified', () => {
// 4. expectation
it('Should have product status as pending approval', () => {
const newProduct = new ProductService().add(...);
expect(newProduct.status).to.equal('pendingApproval');
});
});
});
});
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.