Testcafe 无法识别 React

Testcafe wont recognise React(Testcafe 无法识别 React)
本文介绍了Testcafe 无法识别 React的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试运行我的第一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)