【发布时间】:2016-02-15 09:30:38
【问题描述】:
我正在尝试向我的 Foxx 应用程序添加一些测试。目前,我需要为 Mocha 中的每个测试用例重新创建一条新路由,如下所示:
it('allows POST with JSON encoding', function() {
var app = new Foxx.Controller(applicationContext);
app.post(urlString(), graphqlHTTP({
schema: TestSchema
}));
var res = request(app).post(urlString(), {
body: { query: '{test}' },
json: true
});
expect(res.text).to.equal('{"data":{"test":"Hello World"}}');
});
我在运行测试时遇到了var app = new Foxx.Controller(applicationContext); 这一行的问题:
TypeError: Cannot read property 'push' of undefined
2016-02-14T12:58:58Z [12527] INFO /my-app at new Controller (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/server/modules/org/arangodb/foxx/controller.js:330:19)
2016-02-14T12:58:58Z [12527] INFO /my-app at Context.<anonymous> (/usr/local/var/lib/arangodb-apps/_db/ilearn/my-app/APP/src/__tests__/http-test.js:328:17)
2016-02-14T12:58:58Z [12527] INFO /my-app at Test.Runnable.run (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runnable.js:233:15)
2016-02-14T12:58:58Z [12527] INFO /my-app at Runner.runTest (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:390:10)
2016-02-14T12:58:58Z [12527] INFO /my-app at /usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:473:12
2016-02-14T12:58:58Z [12527] INFO /my-app at next (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:315:14)
2016-02-14T12:58:58Z [12527] INFO /my-app at /usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:325:7
2016-02-14T12:58:58Z [12527] INFO /my-app at next (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:260:23)
2016-02-14T12:58:58Z [12527] INFO /my-app at /usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/node/node_modules/mocha/lib/runner.js:292:5
2016-02-14T12:58:58Z [12527] INFO /my-app at Function.global.DEFINE_MODULE.exports.nextTick (/usr/local/Cellar/arangodb/2.8.0/share/arangodb/js/common/bootstrap/modules/process.js:26:3)
...基本上是说applicationContext.foxxes 是undefined。
我也明白使用全局applicationContext 进行测试不是很明智。但是我怎样才能创建我自己的呢?我还没有找到任何相关文档。
【问题讨论】:
标签: arangodb