Skip to content

Commit 2979fba

Browse files
committed
feat(tests): separate jsx and tsx tests
1 parent 2f327d4 commit 2979fba

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

packages/tests/src/eslint-config-react.test.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
import { eslintConfigReact } from '@azimutlabs/eslint-config-react/lib/config';
22

3+
import { eslintConfigTypescriptBase } from '../../eslint-config-typescript/lib';
34
import { buildEslint } from './services/builders';
45
import { getMessagesFromLintResults } from './services/getMessagesFromLintResults';
56

6-
const eslintBase = buildEslint(eslintConfigReact);
7+
const eslintBase = buildEslint(eslintConfigReact, {
8+
overrideConfig: eslintConfigTypescriptBase,
9+
});
710

811
describe('successful cases', () => {
9-
it('should lint a client-side react component without jsx', async () => {
10-
const file = `import { createElement, forwardRef } from 'react';
12+
it('should lint a client-side typescript react component', async () => {
13+
const file = `import { forwardRef } from 'react';
14+
import type { ReactNode } from 'react';
15+
16+
interface ButtonProps {
17+
readonly disabled?: boolean;
18+
readonly color?: string;
19+
readonly children?: ReactNode;
20+
}
21+
22+
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
23+
({ children, color: _color, ...rest }, ref) => (
24+
<button
25+
ref={ref}
26+
type="button"
27+
{...rest}
28+
>
29+
<span className="d-flex">
30+
{children}
31+
</span>
32+
</button>
33+
),
34+
);
35+
36+
Button.displayName = 'Button';
37+
Button.defaultProps = {
38+
disabled: true,
39+
};
40+
`;
41+
expect(
42+
getMessagesFromLintResults(await eslintBase.lintText(file, { filePath: 'component.tsx' }))
43+
).toStrictEqual([]);
44+
});
45+
46+
it('should lint a client-side jsx react component', async () => {
47+
const file = `import { forwardRef } from 'react';
1148
1249
export const Button = forwardRef(({ children, color: _color, ...rest }, ref) => (
1350
<button
@@ -22,7 +59,6 @@ export const Button = forwardRef(({ children, color: _color, ...rest }, ref) =>
2259
));
2360
2461
Button.displayName = 'Button';
25-
2662
Button.defaultProps = {
2763
disabled: true,
2864
};

packages/tests/src/eslint-config-typescript.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ http.createServer(requestListener).listen(port);
2929
});
3030

3131
it('should lint a client-side react component without jsx', async () => {
32-
const file = `import { createElement, forwardRef } from 'react';
33-
import type { FC } from 'react';
32+
const file = `import { forwardRef } from 'react';
3433
3534
enum Colors {
3635
Blue = 'blue',
@@ -45,27 +44,24 @@ interface ColorProps<C extends Color = AnyColor> {
4544
readonly color: C;
4645
}
4746
48-
interface ButtonProps extends ColorProps<Colors.Blue | Colors.Red> {}
47+
interface ButtonProps extends ColorProps<Colors.Blue | Colors.Red> {
48+
readonly disabled?: boolean;
49+
}
4950
5051
export const isBordered = true;
5152
52-
export const Button: FC<ButtonProps> = forwardRef(({ children, color: _color, ...rest }, ref) =>
53-
createElement(
54-
'button',
55-
{
56-
...rest,
57-
ref,
58-
'aria-disabled': disabled ? 'disabled' : 'not',
59-
},
60-
children,
61-
),
53+
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
54+
({ disabled, color: _color, ...rest }, ref) =>
55+
<button {...rest} ref={ref} aria-disabled={disabled ? 'disabled' : 'not'} />
6256
);
6357
6458
Button.defaultProps = {
6559
disabled: true,
6660
};
6761
`;
68-
expect(getMessagesFromLintResults(await eslintBase.lintText(file))).toStrictEqual([]);
62+
expect(
63+
getMessagesFromLintResults(await eslintBase.lintText(file, { filePath: 'index.tsx' }))
64+
).toStrictEqual([]);
6965
});
7066

7167
it('should lint a next-env.d.ts', async () => {

0 commit comments

Comments
 (0)