Add temporary Sentry test button (dev/test only)
Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { SentryTestButton, handleSentryTestErrorClick } from '../SentryTestButton';
|
||||
|
||||
vi.mock('@sentry/react', () => ({
|
||||
captureException: vi.fn(),
|
||||
logger: { info: vi.fn() },
|
||||
metrics: { count: vi.fn() },
|
||||
}));
|
||||
|
||||
describe('SentryTestButton', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('is visible in the current (development/test) build', () => {
|
||||
render(<SentryTestButton />);
|
||||
expect(screen.getByRole('button', { name: 'Break the world' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('sends a log and a metric to Sentry, then throws an intentional test error', () => {
|
||||
expect(() => handleSentryTestErrorClick()).toThrow('This is your first error!');
|
||||
|
||||
expect(Sentry.logger.info).toHaveBeenCalledWith('User triggered test error', {
|
||||
action: 'test_error_button_click',
|
||||
});
|
||||
expect(Sentry.metrics.count).toHaveBeenCalledWith('test_counter', 1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user