Type safe code, unit tests and CI
Guides
Avo and Unit Tests

Avo and tests

It can be useful to have your Avo Codegen running as a part of your test suite.

To that end, Avo generated tracking libraries can be initialized with a noop flag that disables network requests and only run data validation.

Below is an example of initializing Avo in a jest (opens in a new tab) test environment with JavaScript:

describe('Avo', () => {
  var Avo;
  beforeAll(() => {
    Avo = require('./Avo');
    Avo.initAvo({ env: 'dev', noop: true, strict: true });
  });
  test('signupStart() with email property is valid', () => {
    Avo.signupCompleted({ email: 'test@test.com' });
  });
  test('signupStart() without email property throws', () => {
    expect(() => {
      Avo.signupCompleted();
    }).toThrow();
  });
});

The noop flag is supported in JavaScript, TypeScript, Reason, Java, Objective-C, Swift and Python.

Unit tests in Kotlin and Swift

In the generated Avo file we provide wrapping interface/protocol with all the event methods.

public interface Avo {
    fun feedbackGiven(
        path: String,
        feedback: String
    )
}
public protocol AvoProtocol {
    func feedbackGiven(
        path: String,
        feedback: String
    )
}

We suggest to mock it in your tests and verify that desired method is called with particular parameters.