Search code examples
node.jsunit-testingmocha.jssinontsyringe

How to perform a unit test on the controller layer in a nodejs project with mocha and sinon?


I'm creating an API as a study. I'm very new to programming. I wanted to unit test the controller layer using mocha. I'm using dependency injection with the tsyringe library. In the test I wanted to stub the service layer, and apparently it's not working.

So the test is not working. I tried countless ways, and perhaps due to lack of knowledge, none of them worked. What would be the correct way to implement this test?


Solution

  • something like this should work..

    sinon.stub(service, 'method').resolves() // if method does not return promise, use .returns()