# Sentry Testkit | Sentry for Cloud Functions for Firebase

When building tests for your application, you want to assert that the right flow-tracking or error is being sent to Sentry, but without really sending it to the Sentry servers. This way you won't swamp Sentry with false reports during test runs or other CI operations.

[Sentry Testkit](https://zivl.github.io/sentry-testkit/) is a community-maintained Sentry plugin that allows Sentry's reports to be intercepted for further data inspection. It enables Sentry to work natively in your application, by overriding Sentry's default transport mechanism, which makes it so that the report isn't really sent, but rather logged locally into memory. This way, logged reports can be fetched later for your own usage, verification, or any other purpose you may have in your local developing or testing environment.

Sentry Testkit is community-maintained and not officially supported by Sentry. Please open an issue in the [Sentry Testkit repository](https://zivl.github.io/sentry-testkit/) if you have any questions or feedback.

## [Installation](https://docs.sentry.io/platforms/javascript/guides/firebase/best-practices/sentry-testkit.md#installation)

```bash
npm install sentry-testkit --save-dev
```

### [Using in tests](https://docs.sentry.io/platforms/javascript/guides/firebase/best-practices/sentry-testkit.md#using-in-tests)

```javascript
import sentryTestkit from "sentry-testkit";

const { testkit, sentryTransport } = sentryTestkit();

// initialize your Sentry instance with sentryTransport
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  transport: sentryTransport,
  //... other configurations
});

test("collect error events", function () {
  // run any scenario that eventually calls Sentry.captureException(...)
  expect(testkit.reports()).toHaveLength(1);
  const report = testkit.reports()[0];
  expect(report).toHaveProperty(/*...*/);
});

// Similarly for performance events
test("collect performance events", function () {
  // run any scenario that eventually calls Sentry.startTransaction(...)
  expect(testkit.transactions()).toHaveLength(1);
});
```

You may see more usage examples in the [testing section](https://github.com/zivl/sentry-testkit/tree/master/__tests__) of sentry-testkit repository as well.

### [Testkit API](https://docs.sentry.io/platforms/javascript/guides/firebase/best-practices/sentry-testkit.md#testkit-api)

Sentry Testkit consists of a very simple and straightforward API. See the full API description and documentation in [Sentry Testkit Docs](https://zivl.github.io/sentry-testkit/docs/api).
