dimanche 8 avril 2018

How to check a property of an Object while writing test cases in Ember JS?

I have been doing a small project in Ember JS and with almost 90 percent of the task completed, I went on to write test cases. I wrote an Unit test to check the value of a property stored in the model object of a controller. So, The test is basically a Unit test for the controller.

I will not be able to show the complete code here. However, I will present the structure of the code.

controller.js

import sampleMixin from 'path/sampleMixin';

/* rest of the code goes here */

sampleMixin.js

const { Mixin } = Ember;

export default Mixin.create({
  let self = this;
  this.store.getJSON()
    // Promise goes here
});

The problem is when I run the test case, the test case failed at this.store.getJSON() saying, cannot read store of undefined. When I debugged using a debugger, I found that store was not present. My test case is as follows:

controller-test.js

import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:controller', 'Unit | Controller | controller', {
  needs: ['service:metaData']
});

test('it exists', function(assert) {
  let controller = this.subject();
  assert.ok(controller);
});

I am new to testing environments in Ember, Should I use Unit testing to check the properties of an Object?




Aucun commentaire:

Enregistrer un commentaire