Avo and tests

1 minute read

It can be useful to have your Avo functions 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 test environment with JavaScript:

JavaScript
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.

Kotlin
Copy
1
2
3
4
5
6
public interface Avo {
fun feedbackGiven(
path: String,
feedback: String
)
}
Swift
Copy
1
2
3
4
5
6
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.