0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/mdx/test/mdx-plus-react.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-01-31 03:37:34 -05:00
import * as assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';
function hookError() {
const error = console.error;
const errors = [];
2023-08-31 10:32:51 -05:00
console.error = function (...args) {
errors.push(args);
};
2023-08-31 10:32:51 -05:00
return () => {
console.error = error;
return errors;
};
}
describe('MDX and React', () => {
let fixture;
let unhook;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/mdx-plus-react/', import.meta.url),
});
unhook = hookError();
await fixture.build();
});
it('can be used in the same project', async () => {
const html = await fixture.readFile('/index.html');
const { document } = parseHTML(html);
const p = document.querySelector('p');
2024-01-31 03:37:34 -05:00
assert.equal(p.textContent, 'Hello world');
});
it('mdx renders fine', async () => {
const html = await fixture.readFile('/post/index.html');
const { document } = parseHTML(html);
const h = document.querySelector('#testing');
2024-01-31 03:37:34 -05:00
assert.equal(h.textContent, 'Testing');
});
it('does not get a invalid hook call warning', () => {
const errors = unhook();
2024-01-31 03:37:34 -05:00
assert.equal(errors.length === 0, true);
});
});