Unit Tests

Unit test writing with Jest (JS/TS) or pytest (Python). Test structure, mocking, edge cases, coverage. Don't use for E2E or integration tests.

neuron-one 5155c64 825 B Updated

File contents

Unit Testing

Structure (Arrange-Act-Assert)

describe('ServiceName', () => {
  it('should [expected behavior] when [condition]', () => {
    // Arrange: setup
    // Act: call function
    // Assert: verify result
  });
});

What to Test

  • Happy path (normal operation)
  • Edge cases (empty, null, boundary values)
  • Error cases (invalid input, network failure)
  • Business logic (calculations, transformations)

Mocking

  • Mock external dependencies (DB, API, filesystem)
  • Never mock the thing you're testing
  • Use dependency injection for testability

Coverage Target

  • New code: 80%+ line coverage
  • Critical paths: 100%

neuron-one/godmode/tree/main/skills/testing/unit-tests commit 5155c64b8f

Frequently asked questions

npx skillmds@latest add neuron-one/unit-tests