3

Ember Testing Guides を見ていると、サービスをスタブ化したいときに次のことを行うように書かれています

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 のドキュメントにあります。

4

1 に答える 1