Skip to content

Commit

Permalink
tests: test custom components
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed Apr 3, 2024
1 parent 02434b5 commit b372818
Show file tree
Hide file tree
Showing 5 changed files with 2,827 additions and 1,530 deletions.
2 changes: 1 addition & 1 deletion __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["@readme/eslint-config/testing", "@readme/eslint-config/testing/jest"],
"extends": ["@readme/eslint-config/testing/jest.js", "@readme/eslint-config/testing/vitest.js"],
"rules": {
"testing-library/no-container": "off",
"testing-library/no-node-access": "off"
Expand Down
34 changes: 34 additions & 0 deletions __tests__/custom-components/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { compile, run } from '../../index';
import { renderToString } from 'react-dom/server';
import React from 'react';

describe('Custom Components', () => {
const Example = () => <div>It works!</div>;
const Composite = () => (
<>
<div>Does it work?</div>
<Example />
</>
);

it('renders custom components', () => {
const doc = `
<Example />
`;
const Page = run(compile(doc), { components: { Example } });
const output = renderToString(<Page />);

expect(output).toBe('<div data-reactroot="">It works!</div>');
});

it('renders custom components recursively', () => {
const doc = `
<Composite />
`;

const Page = run(compile(doc), { components: { Example, Composite } });
const output = renderToString(<Page />);

expect(output).toBe('<div>Does it work?</div><div>It works!</div>');
});
});
4 changes: 1 addition & 3 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export const utils = {
const makeUseMDXComponents = (more: RunOpts['components']) => {
const components = { ...Components, ...more };

console.log({ components });

return () => components;
};

Expand All @@ -55,7 +53,7 @@ export const compile = (text: string, opts = {}) => {
providerImportSource: '#',
remarkPlugins: [calloutTransformer],
...opts,
})
}),
);
};

Expand Down
Loading

0 comments on commit b372818

Please sign in to comment.