과 수용 테스트에서 서비스, 엠버 2.7.0와 this is the accepted answer for mocking a service in an acceptance test모의 엠버 엠버 이전 버전 2.7.0
, 나는 위의 대답에 따라의 startApp를 호출 할 수 없습니다입니다. 그러나 몇 가지 빠른 테스트를 통해 서비스를 주입하는 데는 문제가 없습니다.
import Ember from 'ember';
import { module, test } from 'qunit';
let speakerMock = Ember.Service.extend({
speak: function() {
console.log("Acceptance Mock!");
}
});
module('Acceptance | acceptance demo', {
beforeEach: function() {
// the key here is that the registered service:name IS NOT the same as the real service you're trying to mock
// if you inject it as the same service:name, then the real one will take precedence and be loaded
this.application.register('service:mockSpeaker', speakerMock);
// this should look like your non-test injection, but with the service:name being that of the mock.
// this will make speakerService use your mock
this.application.inject('controller', 'speakerService', 'service:mockSpeaker');
}
});
test('visit a route that will trigger usage of the mock service' , function(assert) {
visit('/');
andThen(function() {
assert.equal(currentURL(), '/');
});
});
내가 누락 된 것이 있습니까? 의심스러운 점이 있습니다.
a) 이유가 궁금 하신가요? Embers 문서 provide excellent documentation on stubbing services in components.
b) 수용 테스트에서 서비스를 모의하기를 권장하지 않으십니까? 왜? the guide 가입일
@ykaragol의 대답은 정확합니다. 일반적으로 블랙 박스 기술로 수락 테스트를하는 것이 좋습니다. 그걸로 무엇을 이루고 싶습니까? 어쩌면 우리는 더 적절한 방법을 찾을 수 있습니다. –