Javascript CasperJS 1.1.0-beta2测试示例导致未捕获错误
我很想使用CasperJS对PhantomJS headless浏览器运行测试。有很好的文档,但我想遵循的这个示例不起作用。有没有人能够让它工作,或者有人能发现我的实现有问题?我在CasperJS文档中引用了这个“”:Javascript CasperJS 1.1.0-beta2测试示例导致未捕获错误,javascript,testing,automated-tests,phantomjs,casperjs,Javascript,Testing,Automated Tests,Phantomjs,Casperjs,我很想使用CasperJS对PhantomJS headless浏览器运行测试。有很好的文档,但我想遵循的这个示例不起作用。有没有人能够让它工作,或者有人能发现我的实现有问题?我在CasperJS文档中引用了这个“”: //cow-test-ref.js function Cow() { this.mowed = false; this.moo = function moo() { this.mowed = true; // mootable state: don
//cow-test-ref.js
function Cow() {
this.mowed = false;
this.moo = function moo() {
this.mowed = true; // mootable state: don't do that at home
return 'moo!';
};
}
casper.test.begin('Cow can moo', 2, {
setUp: function(test) {
this.cow = new Cow();
},
tearDown: function(test) {
this.cow.destroy();
},
test: function(test) {
test.assertEquals(this.cow.moo(), 'moo!');
test.assert(this.cow.mowed);
test.done();
}
});
我的结果是以下错误:
m@mPro marketing_qa $ casperjs --version
1.1.0-beta2
m@mPro tests $ casperjs test cow-test-ref.js
Test file: cow-test-ref.js
# Cow can moo
PASS Subject equals the expected value
PASS Subject is strictly true
FAIL TypeError: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# type: uncaughtError
# file: cow-test-ref.js:14
# error: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# TypeError: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# at cow-test-ref.js:14
# at done (/usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:1067)
# at cow-test-ref.js:20
# at /usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:986
# at /usr/local/Cellar/casperjs/1.1-beta2/libexec/bin/bootstrap.js:51
# at begin (/usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:1015)
# at cow-test-ref.js:21
# stack: not provided
FAIL 3 tests executed in 0.023s, 2 passed, 1 failed, 0 dubious, 0 skipped.
有没有人遇到过这个问题,或者成功地解决了这个问题?我很想使用这个测试模式。以
销毁方法为例,强调拆卸背后的原理概念。该方法未在原始代码中实现,因此出现的错误是正常的