httpSnippet.spec.tsx 989 B

1234567891011121314151617181920212223242526272829303132333435
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import {HTTPSnippet} from './httpSnippet';
  3. jest.mock('@sentry/utils', () => ({
  4. ...jest.requireActual('@sentry/utils'),
  5. generateSentryTraceHeader: jest.fn(() => 'sentry-trace-value'),
  6. }));
  7. describe('HTTPSnippet', function () {
  8. it('renders', function () {
  9. const {container} = render(
  10. <HTTPSnippet
  11. url="https://example.com/test?query=value"
  12. method="POST"
  13. body={'{"key": "value"}'}
  14. headers={[['X-Something', 'Header Value']]}
  15. />
  16. );
  17. const expected = [
  18. 'POST /test?query=value HTTP/1.1',
  19. 'Host: example.com',
  20. 'X-Something: Header Value',
  21. 'Sentry-Trace: sentry-trace-value',
  22. 'Content-Size: 18',
  23. ``,
  24. `{"key": "value"}`,
  25. ].join('\r\n');
  26. // XXX(epurkhiser): Using toHaveTextContent would be nice here, but it
  27. // loses the newlines.
  28. expect(container.getElementsByTagName('code')[0].innerHTML).toBe(expected);
  29. });
  30. });