|
I am trying to write unittests for a loopback model using jasmine. My model has the usual CRUD endpoints but I have defined a custom '/products/:id/upload' endpoint which expects a form with files. My model looks like My end goal is to test the logic of the "createProduct". My test looks like By calling ProductModel.upload(); ultimately I would like to trigger the before upload remote hook. I could test "createProduct" in isolation but then I would omit the fact that createProduct ends up being called as a result of upload. So, the core question is:
How do I exercise remote method hooks inside unittests ? Thank you |
it('should load file ', function(){
ProductModel.upload();
});
By calling ProductModel.upload(); ultimately I would like to trigger the before upload remote hook. I could test "createProduct" in isolation but then I would omit the fact that createProduct ends up being called as a result of upload.
So, the core question is: How do I exercise remote method hooks inside unittests ?
Ok so I got this working, however, I am wondering if this is the correct way to do it. Instead of having my app = loopback(), I just go ahead and load the express/loopback app using require.
I wonder why the app = loopback() and app.use(loopback.rest()); doesnt work.