httpSnippet.spec.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {generateSentryTraceHeader} from '@sentry/utils';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import {HTTPSnippet} from './httpSnippet';
  4. jest.mock('@sentry/utils', () => ({
  5. ...jest.requireActual('@sentry/utils'),
  6. generateSentryTraceHeader: jest.fn(() => 'sentry-trace-value'),
  7. }));
  8. describe('HTTPSnippet', function () {
  9. it('renders', function () {
  10. const {container} = 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. // XXX(epurkhiser): Using toHaveTextContent would be nice here, but it
  35. // loses the newlines.
  36. expect(container.getElementsByTagName('code')[0].innerHTML).toBe(expected);
  37. });
  38. });