Заглушение службы при тестировании интеграционных тестов компонентов Ember

Я смотрю на руководства по тестированию Ember, и в них говорится, что нужно сделать следующее, когда вы хотите заглушить службу.

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';

//Stub location service
const locationStub = Ember.Service.extend({
  city: 'New York',
  country: 'USA',
  currentLocation: {
    x: 1234,
    y: 5678
  },

  getCurrentCity() {
    return this.get('city');
  },
  getCurrentCountry() {
    return this.get('country');
  }
});

moduleForComponent('location-indicator', 'Integration | Component | location indicator', {
  integration: true,

  beforeEach: function () {
    this.register('service:location-service', locationStub);
    this.inject.service('location-service', { as: 'location' });
  }
});

Проблема в том, что я получаю Uncaught TypeError: this.register is not a function, когда использую этот код. Итак, я предполагаю, что перед каждым this.register('service:location-service', locationStub); возникает проблема.

Кто-нибудь знает, как я могу обойти это или какой более правильный способ отключить службу? Этот код в настоящее время находится в документации Ember.


person user1952811    schedule 08.11.2015    source источник


Ответы (1)


Похоже, что this.register присутствует только в более поздних версиях ember-qunit, вам нужно убедиться, что вы используете ember-qunit >= 0.4.13.

this.register присутствует только в ember-qunit >= 0.4.13.

http://discuss.emberjs.com/t/service-injection-in-component-integration-tests/8956/3

person Jon Denly    schedule 09.12.2015