labs-description.test.tsx 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { expect } from 'chai'
  2. import { render } from '@testing-library/react'
  3. import { LabsDescription } from '@/shared/components/labs/labs-description'
  4. describe('<LabsDescription />', function () {
  5. it('adds rel and target attributes to rendered links', function () {
  6. const { container } = render(
  7. <LabsDescription description="A [link](https://example.com)." />
  8. )
  9. const link = container.querySelector('a')
  10. expect(link).to.not.equal(null)
  11. expect(link?.getAttribute('href')).to.equal('https://example.com')
  12. expect(link?.getAttribute('rel')).to.equal('noreferrer noopener')
  13. expect(link?.getAttribute('target')).to.equal('_BLANK')
  14. })
  15. it('preserves href sanitization for unsafe links', function () {
  16. const { container } = render(
  17. <LabsDescription description="A [link](javascript:alert(1))." />
  18. )
  19. const link = container.querySelector('a')
  20. expect(link).to.not.equal(null)
  21. expect(link?.getAttribute('href')).to.equal('')
  22. expect(link?.getAttribute('rel')).to.equal('noreferrer noopener')
  23. expect(link?.getAttribute('target')).to.equal('_BLANK')
  24. })
  25. })