问题描述
我正在尝试运行我的第一个 testcafe 测试,但它被证明是艰巨的.
I'm trying to run my first testcafe test but it's proving arduous.
testcafe -e chrome client/routes/Lookup/components/testcafe/lookup-test.js
testcafe -e chrome client/routes/Lookup/components/testcafe/lookup-test.js
SyntaxError: client/routes/Lookup/components/Lookup.js: Unexpected token (60:8)
58 | if (error.status && error.status !== 404) {
59 | return (
> 60 | <NetworkIssues code={error.status} />
| ^
61 | );
62 | }
63 |
at Object.<anonymous> (client/routes/Lookup/components/testcafe/lookup-test.js:1:1)
lookup-test.js
lookup-test.js
import Lookup from '../Lookup';
import React from 'react';
import { waitForReact } from 'testcafe-react-selectors';
fixture('Lookup Component').page('http://localhost:3000/web/lookup').beforeEach(async () => {
await waitForReact();
});
test('foo', async (x) => {
await x
.typeText('customerName', '07450118811')
.expect('customerName.value').contains('07450118811');
});
我的代码没有任何错误.它编译和工作正常,并通过了我所有的笑话和酶单元测试.但是我在网上找不到任何指导.如您所见,忽略错误标志无济于事.
My code doesn't have any errors. It compiles and works fine and passes all my jest and enzyme unit testing. But I can't find any guidance online for this. As you can see the ignore errors flag is used to no avail.
干杯.
推荐答案
当您启动 TestCafe 时,您的所有测试代码都会在执行前作为第一步进行转译.执行的是这个转译过程的结果,而不是您的原始源代码,即使您的代码是纯 JavaScript.
When you start TestCafe, all your test code is transpiled as a first step before execution. What is executed is the result of this transpilation process and not your original source code, even if your code is pure JavaScript.
导入的文件client/routes/Lookup/components/Lookup.js
是一个JSX文件,由于是在TestCafe代码中导入的,所以在开始测试执行前会先将il转译成javascript.
The imported file client/routes/Lookup/components/Lookup.js
is a JSX file, and since it is imported in the TestCafe code, il will be first transpiled to javascript before starting test execution.
TestCafe 转译过程(在撰写本文时 - 将来可能会更改)未配置为处理 JSX 文件.
The TestCafe transpilation process (at the time of writing - it may change in the future) is not configured to handle JSX files.
因此,不能导入TestCafe无法转译成纯JS的文件.
Therefore, you cannot import files that cannot be transpiled into pure JS by TestCafe.
这篇关于Testcafe 无法识别 React的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!