1

私のアプリケーションでは、GooglePlaceRetriever サービスでクラス メソッドをテストしたいと考えています。Ember-Cli でテストするときに this.subject() を使用してサービスのインスタンスを取得できることはわかっていますが、実際の G​​ooglePlaceRetriever オブジェクト自体にアクセスしてクラス メソッドをテストする方法がわかりません。

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

moduleFor('service:google-place-retriever', 'GooglePlaceRetrieverService', {
  // Specify the other units that are required for this test.
  // needs: ['service:foo']
});

// Replace this with your real tests.
test('it exists', function() {
  var service = this.subject();
  ok(service);
});

test('fetches place details from Google and converts it to a location', function()
  //Cannot figure out how to access the Class as opposed to the instance.
  var location = ???.findByPlaceId('ChIJaeKPQD_zz4kRy4c8TvnwGIg');

  ok(location.get('name'), "My Name");
});
4

1 に答える 1

1

次のように、テスト用のクラス メソッドにアクセスできます。

var location = this.subject.constructor.findByPlaceId('whatever');

しかし、なぜクラス メソッドを使用するのでしょうか。サービスをインスタンス化するべきではありませんか?

于 2014-12-24T06:43:31.737 に答える