Mocks and stubs: sinon vs ember-sinon vs ember-sinon-qunit

What is the way to go for mocking and stubbing functions in Ember applications as of 2021?

Some research has shown these three candidates:

  1. Sinon. It is a very well known framework for spies, mocks and stubs. However, it is a standalone library, which I would not be installing via the ember cli
  2. ember-sinon, which had its last commit 2 years ago
  3. ember-sinon-qunit, which claims to be better than ember-sinon if you are using qunit (which I am), but also has almost no activity

I am not against every inactive project by default, but I know that I am assuming certain risks if I go that way. So my question is: which library would be the best bet? I can safely go for one of the two ember libraries, or that is too risky and I should rather stay by the vainilla sinon approach?

Looking at the code ember-sinon doesn’t really do much of anything besides include sinon.js in the build, so I definitely wouldn’t bother with that.

ember-sinon-qunit on the other hand, is doing a lot more to help setup/cleanup sinon within the test runner, so if you decide to roll your own you should certainly take some inspiration and pay attention to the test state as it’s easy to create a scenario where you’re leaking state across tests. It was also updated back in May which isn’t all that long ago. It’s always risky choosing an addon that isn’t like top 5% and clearly well maintained, but in the worst case you can always fork/adapt the code in the future. Also, confusingly, it sounds like this package might be more compatible with mocha, etc:

This addon exists to enable ember-sinon to remove its qunit specific functionality, making it easier to utilize ember-sinon with other addons like ember-cli-mocha, for example.

Personally I’d say it’s probably worth using ember-sinon-qunit. But maybe read over the docs and the code well to understand what all it’s doing for you and decide if it’s worth relying on the addon for that vs doing it yourself.

From personal experience, I would say ember-sinon-qunit is definitely the safest bet. Not necessarily for the support it has, but more for the sandbox cleaning that automatically performs for you. You will prevent memory leaks and flaky tests from wrong/forgetful use of Sinon.JS.