Blog article

As any Ember developer probably knows by now, the error messages shown by failing asserts are far from ideal. Getting a failed, expected argument to be truthy, was: false followed by a stack trace that points to lines on the generated test file (one file with all your compiled tests), can be pretty disappointing when you want to be able to get quick feedback from your tests.

One of the best practices when using QUnit is to always include an error message that explains what’s the purpose of the assertion. This is a good practice but in reality it falls short: developers tend to be lazy and not include all messages, or sometimes the error message and the assertion are one to one equivalent, e.g.: assert.equal(page.title, 'hello world', "Page title is hello world"); Having better errors by default can help in those cases.

As part of our Technical Thursdays’ last cycle, we set out to improve this, looking to both enhance our tests and learn more about ember-cli and its addons.

The result was ember-qunit-nice-errors, a just add water and mix kinda addon 😉

Just install it on your desired project and it will take care of all those asserts on your tests that don’t have a custom message set by you. The following test:

import { module, test } from 'qunit';

module('Unit | example test');

test('it works', function(assert) {
  assert.equal(1, 2);

will go from giving you a message error like:




The addon basically hooks up on your app’s build process, and for all the asserts on the test files that don’t have a custom message (since we don’t want to override your work), it will add a message that tells you the assert method you’re using and the params you’re calling it with.

We hope this improves your quality of life! Or at least makes it easier to find those errors. So try it out! We’re always looking for feedback and ways to improve the project.