gpt4 book ai didi

node.js - phantom 没有方法 'create'

转载 作者:搜寻专家 更新时间:2023-11-01 00:07:46 24 4
gpt4 key购买 nike

我正在尝试将 phamtom 用于 node express 应用程序。

为了测试目的,我写了这个测试

'use strict' ;

var buster = require("buster"),
phantom = require('phantom'),
server="http://localhost:3000";
buster.spec.expose();
describe("get index page", function () {
it("is accessable", function(phantom) {
phantom.create(function (error,ph) {
ph.createPage(function (page) {
... ...
ph.exit();
}
});
});
});
console.log('phatom.create.done') ;
});
});

但是当测试它时

node test/node-test-index.js

对象幻象没有创建方法

TypeError: Object function (fn) {
if (typeof fn !== "function") { return resolve("resolve"); }
return function () {
try {
var retVal = fn.apply(this, arguments);
resolve("resolve");
return retVal;
} catch (up) {
resolve("reject", up);
}
};
} has no method 'create'
at Object.<anonymous> (/home/hebus/Documents/git/system/nodejs/searchEs/test/node-test-index.js:25:15)

最佳答案

如果 it 回调,您将覆盖局部范围内的变量引用。不要重复使用变量名!

it("is accessable", function(done) {

您的代码的另一个错误是 phantom.create() 回调的错误参数。

如果你真的在使用phantom模块,那么你需要改变

phantom.create(function (error,ph) {

phantom.create(function (ph) {

如果没有,那么你应该使用

var phantom = require('node-phantom');

这是 node.js 和 PhantomJS 之间非常相似的桥梁。

关于node.js - phantom 没有方法 'create',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28589720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com