What to do with Qunit's default tests?


#1

The Qunit tests that Ember generates contain some default tests, like:

// Acceptance test for route
test('visiting /login', function(assert) {
  visit('/login');

  andThen(function() {
    assert.equal(currentURL(), '/login');
  });
});
// Integration test for component
test('it renders', function(assert) {
  this.render(hbs`{{login-form}}`);
  assert.equal(this.$().text().trim(), '');
});
// Unit test for controller
test('it exists', function(assert) {
  let controller = this.subject();
  assert.ok(controller);
});

Ember usually adds the comment Replace this with your real tests. But then again, the default tests do test something (does it exist or will it render) and might be of value.

I’m new to testing and have just written my first tests. I’m just curious what you do with these default generated tests. Do you feel it’s good practice to keep them there, or do you consider them pollution and remove them?


#2

Ideally, I try to write a basic test with each component, but if it’s harder to do immediately, I usually delete them until I’m ready to write tests for it. I can see them being a reminder that tests need to be written, but I view them as unnecessary code. A good practice, I think, would be to write a test for your component as your write your component, but if you can’t for whatever reason, I think it’s worth removing the test.


#3

As someone who went from not really doing all that much testing to really embracing test driven development over the last two years — I can say that having these here, even if nothing but a placeholder, has been a great way to make sure testing is never forgotten because once we were really ready to do TDD, we had a starting point. It’s maybe a little bit of unnecessary code bloat, but it doesn’t end up in your app builds so it doesn’t hurt.

Once you are ready to update these tests, however, I would probably not keep the defaults unless they express your intended behavior. (In fact, something like assert.equal(this.$().text().trim(), ''); probably won’t pass unless your component doesn’t render anything).