CasperJS的Hello-test.js运行错误

// hello-test.js
casper.test.begin("Hello, Test!", 1, function(test) {
    test.assert(true);
    test.done();
});

$caspserjs hello-test.js
运行之后出现错误,我是照抄的官网的例子a-minimal-testing-script
帮忙看一下,是什么问题?
error:

$ casperjs test hello-test.js
2016-02-04 11:00:19.878 phantomjs[17344:140800] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
Test file: hello-test.js
FAIL TypeError: 'undefined' is not a function (evaluating 'casper.test.begin("Hello, Test!", 1, function(test) {
    test.assert(true);
    test.done();
})')
#    type: uncaughtError
#    error: "TypeError: 'undefined' is not a function (evaluating 'casper.test.begin(\"Hello, Test!\", 1, function(test) {\n\ttest.assert(true);\n\ttest.done();\n})')"
TypeError: 'undefined' is not a function (evaluating 'casper.test.begin("Hello, Test!", 1, function(test) {
    test.assert(true);
    test.done();
})')
  /Users/wangqi/Documents/workspace/casperjs/hello-test.js:10
FAIL 1 tests executed in 0.014s, 0 passed, 1 failed.

Details for the 1 failed test:

In hello-test.js:0
   uncaughtError: TypeError: 'undefined' is not a function (evaluating 'casper.test.begin("Hello, Test!", 1, function(test) {
    test.assert(true);
    test.done();
})')
阅读 3.5k
1 个回答

目前,CasperJS 稳定版的版本号是 1.0.x,但是官方网站的示例和文档是根据 1.1.x 开发版编写的,其中,begin() 就是从 1.1.x 开始开发的。

所以解决这个问题的方法就是将 CasperJS 的版本升级到 1.1.x 以上,如果是 Mac 平台,可以使用:

brew install casperjs --devel
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题