本文介绍了Testcafe不会认出React的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行我的第一个testcafe测试,但事实证明这很艰巨.

I'm trying to run my first testcafe test but it's proving arduous.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 01:25