2017-12-14 26 views
0

http 요청으로 유닛 테스트를 작성하고 있습니다. 응답으로 다른 필드를 테스트하려고하지만 첫 번째 예외에서 필드를 확인할 때 CHAI가 모두 단일 테스트를 닫습니다. 나는 CHAI가 시험 실행을 계속하기를 원합니다. 어떻게해야합니까?첫 번째 예외 후 계속 테스트 | 차이 티 | Mocha

이것은 expect를 사용하는 방법의 예입니다.

expect(res.body.data.user_data,"last_name").have.property('last_name'); expect(res.body.data.user_data.last_name,"last_name").be.a('number'); expect(res.body.data.user_data,"username").have.property('username'); expect(res.body.data.user_data.username,"username").be.a('string');

+1

'try ... catch' 블록에 넣으면 어떨까요? –

+0

별도의 테스트를 통해 기대치를 높일 수 있습니다. – Robbie

답변

1

당신은 분명히 특정 문을 것 exception 당신이 그것을 테스트하기 위해 다음과 같은 방법을 사용할 수 있습니다 던졌습니다 알고있는 경우. 당신이 확인하고 다음과 같이 trycatch 블록을 사용할 수 있습니다지고 예외 처리하려는 경우

expect(res.body.data.user_data).to.throw('Oh no') 

또는 :

try { 
    expect(res.body.data.user_data, "last_name").have.property('last_name'); 
    expect(res.body.data.user_data.last_name, "last_name").be.a('number'); 
    expect(res.body.data.user_data, "username").have.property('username'); 
    expect(res.body.data.user_data.username, "username").be.a('string'); 
} 
catch (e) { 
    //write err and res objects to custom log file 
    throw e; 
} 

을 나는 주장 후에도 계속 그 수 생각하지 않는다 Chai에 실패했습니다.