반응형
createspy와 createspyobj의 차이점은 무엇입니까?
나는 내 코드에 다음과 같은 것을 사용했다.
return $provide.decorator('aservice', function($delegate) {
$delegate.addFn = jasmine.createSpy().andReturn(true);
return $delegate;
});
createSpy는 어떻게 합니까?createSpy 콜을 createpyobj 콜로 변경할 수 있습니까?
createSpy를 사용하면 함수/메서드 모크를 1개 만들 수 있습니다.createspyobj는 여러 기능 모크를 수행할 수 있습니다.내 말이 맞니?
뭐가 다를까?
jasmine.createSpy
감시 기능이 없을 때 사용할 수 있습니다.콜과 인수를 추적합니다.spyOn
구현은 없습니다.
jasmine.createSpyObj
는 하나 이상의 메서드를 감시하는 모크를 작성하기 위해 사용됩니다.스파이인 각 문자열의 속성을 가진 개체를 반환합니다.
모크를 작성하려면 다음을 사용해야 합니다.jasmine.createSpyObj
아래 예를 참조하십시오.
Jasmine 문서 http://jasmine.github.io/2.0/introduction.html에서...
createSpy:
describe("A spy, when created manually", function() {
var whatAmI;
beforeEach(function() {
whatAmI = jasmine.createSpy('whatAmI');
whatAmI("I", "am", "a", "spy");
});
it("is named, which helps in error reporting", function() {
expect(whatAmI.and.identity()).toEqual('whatAmI');
});
it("tracks that the spy was called", function() {
expect(whatAmI).toHaveBeenCalled();
});
it("tracks its number of calls", function() {
expect(whatAmI.calls.count()).toEqual(1);
});
it("tracks all the arguments of its calls", function() {
expect(whatAmI).toHaveBeenCalledWith("I", "am", "a", "spy");
});
it("allows access to the most recent call", function() {
expect(whatAmI.calls.mostRecent().args[0]).toEqual("I");
});
});
createSpyObj:
describe("Multiple spies, when created manually", function() {
var tape;
beforeEach(function() {
tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']);
tape.play();
tape.pause();
tape.rewind(0);
});
it("creates spies for each requested function", function() {
expect(tape.play).toBeDefined();
expect(tape.pause).toBeDefined();
expect(tape.stop).toBeDefined();
expect(tape.rewind).toBeDefined();
});
it("tracks that the spies were called", function() {
expect(tape.play).toHaveBeenCalled();
expect(tape.pause).toHaveBeenCalled();
expect(tape.rewind).toHaveBeenCalled();
expect(tape.stop).not.toHaveBeenCalled();
});
it("tracks all the arguments of its calls", function() {
expect(tape.rewind).toHaveBeenCalledWith(0);
});
});
언급URL : https://stackoverflow.com/questions/24321307/what-is-the-difference-between-createspy-and-createspyobj
반응형
'programing' 카테고리의 다른 글
루트가 변경되면 Angular UI Bootstrap Modal을 자동으로 닫는 방법이 있나요? (0) | 2023.03.08 |
---|---|
Reference Loop Handling이란?뉴턴소프트에서 무시한다고요? (0) | 2023.03.08 |
각질 소재를 사용한 클래식한 "스틱 푸터" 구현 방법 (0) | 2023.03.08 |
javascript에서 ISO 날짜 개체를 만듭니다. (0) | 2023.03.08 |
Ajax 콜 진행 상황을 보여주는 가장 좋은 방법은 무엇입니까? (0) | 2023.03.08 |