fix(ct): respect boolean shorthands (#14798)
This commit is contained in:
parent
5617e5c613
commit
380e787065
|
|
@ -26,7 +26,7 @@ import { tsConfigLoader } from './third_party/tsconfig-loader';
|
|||
import Module from 'module';
|
||||
import type { BabelTransformFunction } from './babelBundle';
|
||||
|
||||
const version = 11;
|
||||
const version = 12;
|
||||
const cacheDir = process.env.PWTEST_CACHE_DIR || path.join(os.tmpdir(), 'playwright-transform-cache');
|
||||
const sourceMaps: Map<string, string> = new Map();
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ export default declare((api: BabelAPI) => {
|
|||
props.push(t.objectProperty(t.stringLiteral(attrName), jsxAttribute.value));
|
||||
else if (t.isJSXExpressionContainer(jsxAttribute.value) && t.isExpression(jsxAttribute.value.expression))
|
||||
props.push(t.objectProperty(t.stringLiteral(attrName), jsxAttribute.value.expression));
|
||||
else if (jsxAttribute.value === null)
|
||||
props.push(t.objectProperty(t.stringLiteral(attrName), t.booleanLiteral(true)));
|
||||
else
|
||||
props.push(t.objectProperty(t.stringLiteral(attrName), t.nullLiteral()));
|
||||
} else if (t.isJSXSpreadAttribute(jsxAttribute)) {
|
||||
|
|
|
|||
|
|
@ -297,3 +297,27 @@ test('should return root locator for fragments', async ({ runInlineTest }) => {
|
|||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
});
|
||||
|
||||
test('should respect default property values', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'playwright/index.html': `<script type="module" src="/playwright/index.ts"></script>`,
|
||||
'playwright/index.ts': `//@no-header`,
|
||||
'src/label.tsx': `//@no-header
|
||||
export const Label = ({ checked }) => <div>type:{typeof checked} value:{String(checked)}</div>;
|
||||
`,
|
||||
|
||||
'src/label.test.tsx': `
|
||||
//@no-header
|
||||
import { test, expect } from '@playwright/experimental-ct-react';
|
||||
import { Label } from './label';
|
||||
|
||||
test('boolean shorthand', async ({ mount }) => {
|
||||
const component = await mount(<Label checked></Label>);
|
||||
await expect(component).toHaveText('type:boolean value:true');
|
||||
});
|
||||
`,
|
||||
}, { workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue