【问题标题】:Using @wdio/sync from a react typescript project使用来自 react typescript 项目的 @wdio/sync
【发布时间】: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


    【解决方案1】:
    import * as sync from '@wdio/sync';
    

    const sync = import("@wdio/sync");
    

    两者都适合我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 2018-12-31
      • 1970-01-01
      • 2021-04-08
      • 2022-12-01
      • 1970-01-01
      相关资源
      最近更新 更多