jeudi 14 juin 2018

Ember js and Sinon Testing

I am struggling to get this test to work as it is throwing a type error. TypeError: self.store.findRecord(...).then is not a function

Working from the route I have a model set up like the following:

    model(params) {
      let self = this
      const maybeFindTest = self.store.findRecord('test', self.get('test'))
                                .then(function(test) { return test; })
                                .catch(function(error) { if (error.errors[0].status === "404") { self.set('error', true); }});
      return maybeFindTest;
    }

Corresponding test:

    test('model get test record', function(assert) {
      const route = this.subject();
      const number = '12345';
      const fakeTest = { 'test' }
      route.set('test', number);
      route.store.findRecord = stub().withArgs('test', route.get('test')).returns(fakeTest);

      assert.equal(route.model(), fakeTest, 'Proper return value');
      assert.ok(route.store.findRecord.calledOnce, 'findRecord called');
    });

Any ideas what could be throwing this? If I take the then and catch statements out of the model then it successfully runs the test.




Aucun commentaire:

Enregistrer un commentaire