我有茉莉花测试代码,用于测试node.js cassandra-driver是否适当地连接到cassandra。 (是的,我知道数据库连接不是单元测试的主题)
var config = require('../config.js');
var cassandra = require('cassandra-driver');
describe('Testing connectivity regarding to config.js', function() {
it('should connect to cassandra', function() {
var client = cassandra.Client({
contactPoints: config.cassandra.hosts,
keyspace: config.cassandra.keyspace
});
});
});
这给我一个错误如下:
Testing connectivity regarding to config.js should connect to cassandra
TypeError: Object #<Object> has no method 'setMaxListeners' TypeError: Object #<Object> has no method 'setMaxListeners'
at Object.Client (/Users/alkimake/Projects/analist/meta-data-cache/node_modules/cassandra-driver/lib/client.js:51:8)
at Object.<anonymous> (/Users/alkimake/Projects/analist/meta-data-cache/spec/connect-spec.js:12:32)
at attemptSync (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1620:12)
at QueueRunner.run (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1608:9)
at QueueRunner.execute (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1595:10)
at Spec.Env.queueRunnerFactory (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:508:35)
at Spec.execute (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:295:10)
at Object.<anonymous> (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1834:37)
at attemptAsync (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1644:12)
at QueueRunner.run (/usr/local/lib/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1606:16)
答案 0 :(得分:0)
您必须使用“new”关键字构建新实例。
var client = new cassandra.Client({...});