Exception Logging
TestFairy allows developers to log up to five exceptions or errors for a given session.
Note: This does not mark the sessions as crashed; it will only log the exception or error to the session.
Syntax
TestFairy.logThrowable(<throwable exception>);
Code Example
// Be sure to import TestFairy import com.testfairy.TestFairy; TestFairy.logThrowable(new Throwable("Some Message"));
Syntax
[TestFairy logError:<NSError>];
[TestFairy logError:<NSError> stacktrace:<NSArray<NSString>>];
Code Example
// Be sure to import TestFairy #import "TestFairy.h" [TestFairy logError:[NSError errorWithDomain:@"com.your.domain" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Some Message"}]];
Syntax
TestFairy.logError(<NSError>)
TestFairy.logError(<NSError>, stacktrace:<[String]>)
Code Example
let error = NSError(domain: "com.your.domain", code: -1, userInfo: [NSLocalizedDescriptionKey : "Some Message"]) TestFairy.logError(error)
Syntax
TestFairy.logException(<Error>);
Code Example
var error = new Error("Some Message"); TestFairy.logException(error);
We recommend adding a listener to the window
to capture error
statements, which will automatically send the exception to TestFairy sessions. One suggestion we have is to add a method that looks like this:
window.addEventListener("error", function(e) { TestFairy.logException(e); });
Syntax
TestFairy.logException(<Error>);
Code Example
// Be sure to import TestFairy const TestFairy = require('react-native-testfairy'); var error = new Error("Some Message"); TestFairy.logException(error);
We recommend replacing the Global Handler with a custom method, which will automatically send the exception to TestFairy sessions. One suggestion we have is to add a method that looks like this:
var ErrorUtils = require('ErrorUtils'); var originalGlobalHandler = ErrorUtils.getGlobalHandler(); ErrorUtils.setGlobalHandler((error, isFatal) => { TestFairy.logException(error); originalGlobalHandler.handleException(error, isFatal); });
Syntax
TestFairySDK.logException(<Error>);
Code Example
// Be sure to import TestFairy import { TestFairySDK } from 'nativescript-testfairy'; var error = new Error("Some Message"); TestFairySDK.logException(error);
We recommend adding a listener to the window
to capture error
statements, which will automatically send the exception to TestFairy sessions. One suggestion we have is to add a method that looks like this:
window.addEventListener("error", function(e) { TestFairy.logException(e); });
Last updated on 2022-12-07