-
Notifications
You must be signed in to change notification settings - Fork 2.2k
AngularFirePerformance incompatible with Jest #2812
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
Line 61 of performance.ts looks like it may be the culprit: it's assumed here that if you have const trace$ = (traceId: string) => {
if (typeof window !== 'undefined' && window.performance) {
const entries = window.performance.getEntriesByName(traceId, 'measure') || [];
const startMarkName = `_${traceId}Start[${entries.length}]`;
const endMarkName = `_${traceId}End[${entries.length}]`;
return new Observable<void>(emitter => {
window.performance.mark(startMarkName);
emitter.next();
return {
unsubscribe: () => {
window.performance.mark(endMarkName);
window.performance.measure(traceId, startMarkName, endMarkName);
}
};
});
} else {
return EMPTY;
}
}; |
as a work around, adding the following to your jest.ts will fix it as well: Object.defineProperty(window.performance, 'mark', {
value: () => mock()
});``` |
Will be addressed in next patch |
If I import
AngularFirePerformance
anywhere reachable by my Jest unit tests (part of@nrwl/nx
) I getTypeError: window.performance.mark is not a function
The error is right on the import, no additional code needed.
The likelihood is this is an incompatibility with Jest's performance-related code. Trying to copy over values from
perf_hooks
didn't work although it changed the error reports. I am opening the issue here to see if anyone has ideas how to fix this. I am using the latest stable versions of everything.The text was updated successfully, but these errors were encountered: