环回模型的unit testing

我有一个模型Student的Loopback API。

如何在不调用REST API的情况下为Student模型的节点API方法编写unit testing? 我找不到任何文档或示例通过节点API本身testing模型。

任何人都可以请帮忙?

testingcount方法的示例

 // With this test file located in ./test/thistest.js var app = require('../server'); describe('Student node api', function(){ it('counts initially 0 student', function(cb){ app.models.Student.count({}, function(err, count){ assert.deepEqual(count, 0); }); }); }); 

这样您就可以testing节点API,而无需调用REST API。

但是,对于内置的方法,这个东西已经被stronglooptesting过了,所以对于testing节点API来说应该是无用的。 但对于远程(=自定义)方法,它仍然是有趣的。

编辑:为什么这种做事方式不明确的原因是因为最终,您将需要testing您的完整的REST API,以确保不仅节点API按预期工作,而且该ACL已正确configuration,返回代码等所以最终你最终会为同样的事情写两个不同的testing,这是浪费时间。 (除非你喜欢写testing:)