mdx-plus-react.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { describe, it, before } from 'node:test';
  2. import * as assert from 'node:assert/strict';
  3. import { parseHTML } from 'linkedom';
  4. import { loadFixture } from '../../../astro/test/test-utils.js';
  5. function hookError() {
  6. const error = console.error;
  7. const errors = [];
  8. console.error = function (...args) {
  9. errors.push(args);
  10. };
  11. return () => {
  12. console.error = error;
  13. return errors;
  14. };
  15. }
  16. describe('MDX and React', () => {
  17. let fixture;
  18. let unhook;
  19. before(async () => {
  20. fixture = await loadFixture({
  21. root: new URL('./fixtures/mdx-plus-react/', import.meta.url),
  22. });
  23. unhook = hookError();
  24. await fixture.build();
  25. });
  26. it('can be used in the same project', async () => {
  27. const html = await fixture.readFile('/index.html');
  28. const { document } = parseHTML(html);
  29. const p = document.querySelector('p');
  30. assert.equal(p.textContent, 'Hello world');
  31. });
  32. it('mdx renders fine', async () => {
  33. const html = await fixture.readFile('/post/index.html');
  34. const { document } = parseHTML(html);
  35. const h = document.querySelector('#testing');
  36. assert.equal(h.textContent, 'Testing');
  37. });
  38. it('does not get a invalid hook call warning', () => {
  39. const errors = unhook();
  40. assert.equal(errors.length === 0, true);
  41. });
  42. });