Testing approach
Nango’s testing framework is built on three core concepts:- Dry runs: Test your integrations against live API connections without affecting production data
- Mocks: Save API responses during dry runs to create reproducible test fixtures
- Snapshot testing: Automatically compare integration outputs against saved snapshots using Vitest
Dry run testing
Dry runs allow you to execute your syncs and actions against real API connections without saving data to your database. This is essential for:- Testing integration logic before deployment
- Debugging issues with live data
- Generating test fixtures (mocks)
- Validating data transformations
Basic dry run
Execute a sync or action against an existing connection:Dry run options
Common options for testing:Data validation
Validation ensures your integration inputs and outputs match your defined schemas. This catches data transformation errors early.Enable validation during dry runs
Use the--validate flag to enforce validation:
- Action inputs are validated before execution
- Action outputs are validated after execution
- Sync records are validated before they would be saved
- Validation failures halt execution and display detailed error messages
Validation with Zod
You can also validate data directly in your integration code using Zod:Validation error output
When validation fails, you’ll see detailed error information:Saving mocks for tests
Mocks are saved API responses that allow you to run tests without hitting external APIs. This makes tests faster and more reliable.Generate mocks with dry run
Use the--save flag to save all API responses:
--save, validation is automatically enabled. Mocks are only saved if validation passes, ensuring your test fixtures contain valid data.
Mock file structure
Mocks are saved in thetests/mocks directory:
Using stubbed metadata
For syncs that rely on connection metadata, you can provide test metadata:Testing with Vitest
Nango uses Vitest as its testing framework. Vitest is fast, has a great developer experience, and provides snapshot testing out of the box.Setup
Install Vitest as a dev dependency:Auto-generated tests
When you runnango generate:tests, Nango creates test files for all your integrations:
Sync test example:
How mocks work in tests
TheNangoSyncMock and NangoActionMock classes automatically load your saved mocks:
- API requests are intercepted and return saved mock responses
- Input data is loaded from
input.json(for actions) - Expected outputs are loaded from the appropriate mock files
- Tests compare actual outputs against expected outputs
- Tests run instantly (no API calls)
- Tests are deterministic (same input = same output)
- Tests work offline
Running tests
Test configuration
Vitest is configured viavite.config.ts in your project root:
vitest.setup.ts file makes Nango mocks available globally:
Customizing tests with business logic
While auto-generated tests validate basic data flow, you often need custom tests for business logic.Adding custom assertions
Extend the generated tests with additional assertions:Testing error handling
Test how your integration handles errors:Testing pagination
Verify pagination logic works correctly:Testing incremental syncs
Test that incremental sync logic works:Parameterized tests
Test multiple scenarios with different inputs:Related resources
- Data Validation - Learn more about schema validation
- Vitest Documentation - Official Vitest docs
- Actions - Building and testing actions
- Syncs - Building and testing syncs