【发布时间】:2020-03-29 07:25:07
【问题描述】:
我正在向我的 react/typescript 应用程序添加一些浏览器测试。
编译器选项:
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": ["es2017", "dom"],
"module": "esnext",
"moduleResolution": "node",
"target": "es6"
}
我在这里遵循样板示例:https://github.com/erwinheitzman/jest-webdriverio-standalone-boilerplate
在测试中有这样的声明(在一些模组之后):
import { BrowserObject } from '@wdio/sync';
const **sync** = require('@wdio/sync').default; // Warnings here
test('synchronous WebdriverIO test', () => **sync**(() => {
...snip...
}));
我收到警告:
require statement not part of an import statement (no-var-requires)tslint(1)
我到底如何在这里使用 import 语句?
import sync = require('...').default; // Doesn't work. Says Declaration or statement expected.ts(1128)
import sync from '...'; // Doesn't work. Says Cannot use namespace 'sync' as a value.ts(2708)
我对这整件事感到很困惑。据我所知,sync 的意思是“使用 wdio/sync 中的 WebDriverIO 命名空间”。有办法导入吗?!?
【问题讨论】:
标签: javascript typescript webdriver-io