Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add exports util with tests #1045

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/lib/exports/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import singleExportMdx from './input/singleExport.mdx?raw';
import multipleExportsMdx from './input/multipleExports.mdx?raw';
import weirdExportsMdx from './input/weirdExports.mdx?raw';
import { exports } from '../../../lib';

describe('export tags', () => {
it('returns a single export name', () => {

expect(exports(singleExportMdx)).toStrictEqual(['Foo']);
});
it('returns multiple export names', () => {

expect(exports(multipleExportsMdx)).toStrictEqual(['Foo', 'Bar']);
});
it('returns different types of export names', () => {

expect(exports(weirdExportsMdx)).toStrictEqual(['Foo', 'bar', 'doSomethingFunction', 'YELLING']);
});
});
12 changes: 12 additions & 0 deletions __tests__/lib/exports/input/multipleExports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export const Foo = () => {
return <div>Hello World</div>;
}

export const Bar = () => {
return <Foo />;
}

## Hey there
<Foo />
8 changes: 8 additions & 0 deletions __tests__/lib/exports/input/singleExport.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

export const Foo = () => {
return <div>Hello World</div>;
}

## Hey there
<Foo />
19 changes: 19 additions & 0 deletions __tests__/lib/exports/input/weirdExports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

export function Foo() {
return <div>Hello World</div>;
}

export const bar = () => {
return <Foo />;
}

export function doSomethingFunction(input) {
return input.trim();
}

export const
YELLING = () => {}

## Hey there
<Foo />
3 changes: 2 additions & 1 deletion __tests__/lib/hast.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hast, hastFromHtml } from '../../lib';
import { hast } from '../../lib';
import { h } from 'hastscript';

describe('hast transformer', () => {
Expand All @@ -19,6 +19,7 @@ describe('hast transformer', () => {
h('h2', { id: 'its-coming-from-within-the-component' }, "It's coming from within the component!"),
);

// @ts-ignore
expect(hast(md, { components })).toStrictEqualExceptPosition(expected);
});
});
Loading
Loading