How can I use WebStorm to create a Cucumber step definition file in TypeScript instead of JavaScript?(如何使用 WebStorm 在 TypeScript 而不是 JavaScript 中创建 Cucumber 步骤定义文件?)
问题描述
我正在使用 Cucumber.js 构建一个新的 e2e 测试套件,并且我想将 TypeScript 用于我的步骤文件.当我创建一个新步骤并按 Alt+Enter
让 WebStorm 生成一个新步骤文件时,我看到的唯一选项是创建一个 JavaScript 文件.
I'm building a new e2e test suite using Cucumber.js and I'd like to use TypeScript for my step files. When I create a new step and I press Alt+Enter
to have WebStorm generate a new step file the only option I am presented with is to create a JavaScript file.
有谁知道如何在 TypeScript 中创建一个新的步骤文件?
Does anyone know how I can make this create a new step file in TypeScript?
推荐答案
Webstorm 似乎没有为文件类型TypeScript"提供向导,因此您可能需要手动创建步骤定义文件.
Webstorm doesn't seem to provide a wizard for file type "TypeScript" so you might want to create your step definition file manually.
对于 简单数学示例,可能的 TS 步骤定义文件可能如下所示:
For the Simple Math Example a possible TS step definition file might look like this:
import * as cucumber from "cucumber";
module.exports = function () {
// Assign this to a typed variable so we have type-safe access
let sd: cucumber.StepDefinitions = this;
// The common variable is simply kept in function scope here
let variable: number = 0;
sd.Given(/^a variable set to (d+)$/, (value: string) => {
variable = parseInt(value);
});
sd.When(/^I increment the variable by (d+)$/, (value: string) => {
variable += parseInt(value);
});
sd.Then(/^the variable should contain (d+)$/, (value: string) => {
if (variable != parseInt(value))
throw new Error('Variable should contain '+value
+ ' but it contains ' + variable + '.');
});
};
将此内容放入例如features/step_definitions/mathSteps.ts 并将 示例 中的功能代码粘贴到名为 e.g.features/math.feature 你应该有一个运行的例子.
Put this content in e.g. features/step_definitions/mathSteps.ts and paste the feature code from the example into a file called e.g. features/math.feature and you should have a running example.
这篇关于如何使用 WebStorm 在 TypeScript 而不是 JavaScript 中创建 Cucumber 步骤定义文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 WebStorm 在 TypeScript 而不是 JavaScript 中创建 Cucumber 步骤定义文件?


- 从原点悬停时触发 translateY() 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01