vendredi 17 février 2017

ember unit test for object depending on model

I have a unit test for an Ember.Object that depends on an ember data model.

I set up the test as:

let application, store, sheet;

moduleFor('model:filter-tree', 'Unit | Model | filter tree', {
  // Specify the other units that are required for this test.
  needs: ['model:view/series'],
  beforeEach() {
    application = startApp();
    store = application.__container__.lookup('service:store');
    sheet = store.createRecord('view/series', { ... });
  },
  afterEach() {
    Ember.run(application, 'destroy');
  }
});

[NB would prefer before() not beforeEach()...]

Then I have a series of tests which use sheet to test the filter-tree object.

If I run one test individually in the browser, everything works. However, when I run the whole series of tests, sheet is not defined, and store.peekRecord('view/series', '1') returns no sheets. (NB '1' is in fact the ID of the test sheet created.)

1) What is happening? How can I get it to work consistently?

2) Is there any way to setup this fixture once and for all, as it is used by many tests?

NB:

$ ember version
ember-cli: 2.12.0-beta.1
node: 7.2.1
os: darwin x64




Aucun commentaire:

Enregistrer un commentaire