Skip to main content

Overview

Testing ensures your Meteor application works as expected and helps prevent regressions as your codebase evolves. Meteor provides built-in testing support with the meteor test command and integrates with popular testing frameworks.

Types of Tests

Unit Tests

Test individual modules in isolation:
  • Fast execution
  • Focused scope
  • Mock dependencies
  • Test pure functions

Integration Tests

Test multiple modules working together:
  • More comprehensive
  • Test real interactions
  • Client-server communication
  • Database operations

End-to-End (E2E) Tests

Test complete user workflows:
  • Browser automation
  • Full application testing
  • Real user scenarios
  • Slowest but most realistic

Test Modes

Meteor provides two test modes:

Test Mode

  • Loads files matching *.test.js or *.spec.js
  • Does not load application code automatically
  • Must import code you want to test
  • Sets Meteor.isTest to true
  • Uses clean test database

Full App Test Mode

  • Loads files matching *.app-test.js or *.app-spec.js
  • Does load application code
  • Sets Meteor.isAppTest to true
  • Better for integration tests

Setting Up Testing

Install Test Driver

Run Tests

Writing Unit Tests

Basic Test Structure

Testing Methods

Testing Publications

Test Data Management

Resetting the Database

Using Factories

Client-Side Testing

Stubbing Collections

Integration Tests

Full-App Tests

Testing Client-Server Communication

Testing Async Code

Continuous Integration

GitHub Actions Example

Best Practices

Test Organization

Writing Good Tests

Follow the AAA pattern: Arrange, Act, Assert