httpSnippet.spec.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {generateSentryTraceHeader} from '@sentry/core';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {HTTPSnippet} from './httpSnippet';
  4. jest.mock('@sentry/core', () => ({
  5. ...jest.requireActual('@sentry/core'),
  6. generateSentryTraceHeader: jest.fn(() => 'sentry-trace-value'),
  7. }));
  8. describe('HTTPSnippet', function () {
  9. it('renders', function () {
  10. render(
  11. <HTTPSnippet
  12. url="https://example.com/test?query=value"
  13. method="POST"
  14. body={'{"key": "value"}'}
  15. headers={[['X-Something', 'Header Value']]}
  16. traceSampling={false}
  17. />
  18. );
  19. expect(jest.mocked(generateSentryTraceHeader)).toHaveBeenCalledWith(
  20. undefined,
  21. undefined,
  22. false
  23. );
  24. const expected = [
  25. 'POST /test?query=value HTTP/1.1',
  26. 'Host: example.com',
  27. 'X-Something: Header Value',
  28. 'User-Agent: SentryUptimeBot/1.0 (+http://docs.sentry.io/product/alerts/uptime-monitoring/)',
  29. 'Sentry-Trace: sentry-trace-value',
  30. 'Content-Size: 18',
  31. ``,
  32. `{"key": "value"}`,
  33. ].join('\r\n');
  34. const codeElem = screen.getByText('POST /test?query=value HTTP/1.1', {exact: false});
  35. // Using toHaveTextContent would be nice here, but it loses the newlines.
  36. expect(codeElem.innerHTML).toBe(expected);
  37. });
  38. });