import * as React from 'react';
import { render } from '../src/renderer';
test('should render plain text', () => {
expect((render('abcd') as string).trim()).toBe('abcd');
});
test('should render numbers as text', () => {
expect((render(123) as string).trim()).toBe('123');
});
test('should render null and not fail for empty values', () => {
expect(render(null)).toBe(null);
expect(render(undefined)).toBe(null);
expect(render([])).toBe(null);
});
test('should render plain text with simple Function Component', () => {
function TestComponent() {
return 'abcd';
}
// Note: Rendering string from function comp shows TS error (https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544). This is a workaround.
expect(
(render(
React.createElement((TestComponent as unknown) as React.FunctionComponent)
) as string).trim()
).toBe('abcd');
});
test('should render plain text with simple Class Component', () => {
class TestComponent extends React.Component {
render() {
return 'abcd';
}
}
expect((render(
abcd
) as string).trim()).toBe('abcd'); }); test('should render plain h1 with text', () => { expect((render(
) as string).trim()
).toBe('');
});
test('should render image with only alt text', () => {
expect(
(render(
) as string).trim()
).toBe('');
});
test('should render image with only title', () => {
expect(
(render(
) as string).trim()
).toBe('');
});
test('should render image without attributes', () => {
expect((render(
) as string).trim()).toBe(
''
);
});
test('should render link with text and title', () => {
expect(
(render(
some text
) as string).trim()
).toBe('[some text](./test "some title")');
});
test('should render link with only text', () => {
expect((render(some text) as string).trim()).toBe(
'[some text](./test)'
);
});
test('should render link with only title', () => {
expect(
(render() as string).trim()
).toBe('[](./test "some title")');
});
test('should render link without title and text', () => {
expect((render() as string).trim()).toBe('[](./test)');
});
test('should render blockquote with plain text', () => {
expect((render(some text) as string).trim()).toBe( '> some text' ); }); test('should render blockquote with mixed text', () => { expect( (render(
) as string).trim() ).toBe('> This is _hello_ **world**'); });This is hello world