传递class
作为参数来访问静态方法。 Evaluate似乎不应该通过它。我已经调试了似乎具有有效参数的line,但是当我在内部调用resolve method
时,它将引发错误
Cannot read property 'resolve' of undefined
该类只包含简单的静态方法,如
class App {
public static resolve() { return true };
}
测试如下
//abc.test.ts
it('should contain "abc" text in Href', (done) => {
nightmare
.goto("abc.com")
.evaluate((driver: any) => {
console.log('driver', driver.resolve()); also is there a way to console.log in evaluate?
return document.getElementById("a").textContent;
}, App)
.end()
.then((response: any) => {
expect(response).to.have.containIgnoreSpaces("abc");
done();
})
.catch((error: any) => console.log("Error", error));
});
npm命令运行测试
set DEBUG=nightmare && mocha --recursive --require jsdom-global/register --require ts-node/register --require babel-core/register tests/*
最佳答案
评估将使所有内容严格化,您将失去自己的类(class)或任何种类的功能。
这个here是另一个名为Puppeteer的库的答案,但是对于您的 Nightmare 脚本也很方便。
那你应该
关于javascript - 将类作为参数传递给 Nightmare 评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48185648/