Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (30 sloc) 1.72 KB
title sidebar_order
Sentry Testkit
30002

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

Sentry Testkit is a Sentry plugin that allows intercepting Sentry's reports and further inspection of the data being sent. It enables Sentry to work natively in your application, and by overriding the default Sentry's transport mechanism, the report is not really sent, but rather logged locally into the memory. This way, logged reports can be fetched later for your own usage, verification, or any other use you may have in your local developing/testing environment.

Installation

npm install sentry-testkit --save-dev

Using in tests

const sentryTestkit = require("sentry-testkit")

const { testkit, sentryTransport } = sentryTestkit()

// initialize your Sentry instance with sentryTransport
Sentry.init({
  dsn: 'some_dummy_dsn',
  transport: sentryTransport
  //... other configurations
})

// then run any scenario that should call Sentry.catchException(...)

expect(testKit.reports()).toHaveLength(1)
const report = testKit.reports()[0]
expect(report).toHaveProperty(/*...*/)

You may see more usage examples in the testing section of sentry-testkit repository as well.

Testkit API

Sentry Testkit consists of a very simple and straightforward API. See the full API description and documentation in Sentry Testkit Docs.

You can’t perform that action at this time.