forked from BuilderIO/mitosis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.test.ts
38 lines (33 loc) · 1.54 KB
/
context.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { parseJsx } from '../parsers/jsx';
import { contextToReact } from '../generators/context/react';
import { parseContext } from '../parsers/context';
import { componentToReact } from '../generators/react';
import { componentToReactNative } from '../generators/react-native';
import simpleExample from './data/context/simple.context.lite.ts?raw';
import componentWithContext from './data/context/component-with-context.raw.tsx?raw';
import renderBlock from './data/blocks/builder-render-block.raw.tsx?raw';
describe('Context', () => {
test('Parse context', () => {
const component = parseContext(simpleExample, { name: 'SimpleExample' });
if (!component) {
throw new Error('No parseable context found for simple.context.lite.ts');
}
expect(component).toMatchSnapshot();
const reactContext = contextToReact()({ context: component });
expect(reactContext).toMatchSnapshot();
});
test('Use and set context in components', () => {
const component = parseJsx(componentWithContext);
expect(component).toMatchSnapshot();
const reactComponent = componentToReact()({ component });
expect(reactComponent).toMatchSnapshot();
const reactNativeComponent = componentToReactNative()({ component });
expect(reactNativeComponent).toMatchSnapshot();
});
test('Use and set context in complex components', () => {
const component = parseJsx(renderBlock);
expect(component).toMatchSnapshot();
const reactComponent = componentToReact()({ component });
expect(reactComponent).toMatchSnapshot();
});
});