简体   繁体   中英

Unit testing a function without any response

I have the following function written in an Ember route

  delete(line) {
    line.destroyRecord().then(() => {
      this.store.unloadRecord(line);
      this.controller.get('deliveryLines').removeObject(line);
    });
  },

My question is, should I write unit tests to cover it ?

After all, the function does not return anything, and does not have any side effects. Should I write unit tests to cover that the function is calling eg destroyRecord or unloadRecord ?

You should write a unit test to cover it, because although it isn't doing anything of importance now, later it could save you from having to debug something that could be caused by this not being called.

Additionally it never hurts to know that your function is behaving the way it should.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM