【发布时间】:2025-12-10 11:50:02
【问题描述】:
好的,所以我有一个使用 cucumberjs 的自动化存储库。我的 world.js 文件变得相当大,我正在尝试将其拆分,以便更易于组织。我试图通过原型划分文件并组合它-
// features/support/world.js
const foo = require('./foo.js');
class customWorldObject {
bar(number) {
//do stuff;
}
}
customWorldObject.prototype.foo = foo;
setWorldConstructor(customWorldObject);
但稍后在步骤函数中
// features/support/steps.js
const { Given, When, Then } = require("@cucumber/cucumber");
const assert = require("assert").strict;
When("I increment the variable by {int}", async function (number) {
this.bar(number);
});
When("the variable should blah blah blah", async function() {
this.foo();
});
当我运行这只小狗时,它似乎没有添加功能
TypeError: this.foo 不是函数
那么我怎样才能正确地将 cucumberjs 世界对象分成单独的文件呢?
【问题讨论】:
标签: node.js cucumberjs