2013-09-27 4 views
3

나는 시험에서 getUserMedia의 콜백에 포함되어 모카 내 테스트 코드의 일부에 붙어 오전 :모카 : (완료) 및 콜백 오류가

여기
it("should work without error", function() { 
    navigator.getUserMedia({fake:true}, function(stream) { 
     expect(3).to.equal(3); 
     done(); // done is not defined if expect() is valid 
    },console.error); 
}); 

은() 일이 아니다 정의되었지만 테스트가 성공적입니다. 여기

it("should NOT work", function() { 
    navigator.getUserMedia({fake:true},function(stream) { 
     expect(3).to.equal(4); 
     done(); 
    },console.error); 
}); 

, 나는 오류가 점점 오전 :

AssertionError: expected 3 to equal 4 

을하지만, 검증으로 모카 인터페이스는 아직 테스트를 보여줍니다. (녹색 진드기)

내가 뭔가 잘못하고 있거나() 도청 당했습니까?

답변

3

함수에 완료 인수가 있어야합니다. 이 시험은 다음과 같이해야하지 않을 경우 당신은 테스트 에서 비동기 기능이있는 경우에만 수행 사용해야하지만

it("should get done", function(done) { 
    expect(3).to.equal(3); 
    expect(3).not.to.equal(4); 
}); 

:

it("should not be async", function() { 
    expect(3).to.equal(3); 
} 
관련 문제