3 Minutes With Kent

Nested Unit Tests: An Anti-Pattern

Informações:

Sinopse

At first I was really bothered that AVA (http://npm.im/ava) didn't have support for nested tests, but now I consider nesting tests to be an anti-pattern. Here's an example of the kind of thing I mean (see this in a syntax-highlighted gist here (https://gist.github.com/kentcdodds/576c16d2069b3535aa4d7435082b186a)): Mocha with nesting (don't mind the actual tests, just imagine what this would be like with a larger test file): ```javascript import Customers from './Customers' import getMockCustomers from './Customers/mocks' describe('Customers', () => { let mockCustomers beforeEach(() => { Customers.setCustomers([]) // initialize to empty for most tests mockCustomers = getMockCustomers() // have mock customers available }) afterEach(() => { Customers.setCustomers([]) // clean up just in case }) describe('getCustomers', () => { beforeEach(() => { Customers.setCustomers(mockCustomers) }) it('should return the existing customers', () => { const customers = Customers.getCustom