나는 재스민에 다음과 같은 기능 검사가 있습니다
이$scope.myFunction = function(param){
if(param === $scope.variable){
$scope.variable = null;
}
else{
$scope.variable = param;
}
});
기능은 위의 전달 된 매개 변수를 사용하고 $scope.variable
비교합니다 : 내 컨트롤러에서
describe("myFunction test", function(){
it("should set $scope.variable to 'test'", function(){
scope.myFunction("test");
expect(scope.variable).toBe("test"); //This passes
console.log(scope.variable); // This logs "test"
});
it("should set $scope.variable to null", function(){
console.log(scope.variable); // Shouldn't this log "test" and not undefined?
scope.myFunction("test");
expect(scope.variable).toBeNull();
})
});
내 기능은 같다. 두 값이 일치하면 $scope.variable
이 null
으로 설정됩니다. 그렇지 않으면 $scope.variable
이 매개 변수의 값으로 변경됩니다.
제 재 스민 테스트에서 scope.variable
이 it
문에 설정된 후에 값이 다음 it
문으로 이월되지 않는 것으로 나타났습니다.진술서가 호출 될 때마다 재 스민 테스트의 $scope
변수가 저장되지 않습니까?
나머지 재 스민 스크립트를 게시 할 수 있습니까? 주사는 어떻게 생겼지? 주사가'beforeEach'에있는 경우,'it' 함수 앞에'scope'를 다시 주입하기 때문에 재설정 될 수 있습니다. –
@j_buckley 나는 컨트롤러 스코프를 생성/주입하고있는 파일의 상단에 (before individual 'describe')'beforeEach'를 가지고 있습니다. 나는 이것이 각각의'describe' 블록 앞에 새로운 범위가 만들어 졌음을 의미하고, 각 블록 내에서 모든'it' 문은 여전히'scope' 변수의 동일한 집합에 대해 작용할 것이라는 인상을 받았습니다. 이것이 올바른 가정입니까? –