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 a single.test.json file that can be used alongside your test file:
test.json file contains all the necessary mock data for a given test:
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 from the .test.json file:
- API requests are intercepted and return saved mock responses from the
apisection. - Input data is loaded from the
inputproperty (for actions). - Expected outputs are loaded from the
outputproperty. - Tests compare actual outputs against expected outputs.
- Tests run instantly (no API calls)
- Tests are deterministic (same input = same output)
- Tests work offline
Migrating from the old format
If you have tests using the old multi-file mock format, you can automatically migrate them to the new unified format. Set theMIGRATE_MOCKS environment variable to true and run your tests:
- Run your tests using the old mock files.
- Intercept all mock data accessed during the test run.
- Save the data into a new
.test.jsonfile. - The old mock directory can then be safely deleted.
Note: This migration tool works by intercepting the mock data loaded by your existing tests. It requires that your tests are using the standard Nango mock utilities (NangoSyncMockorNangoActionMock) imported fromnango/test.
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