2017-09-17 5 views
1

저는 재스민 노드와 함께 Frisy를 사용하여 Meteor API를 테스트합니다.자스민 - 노드가있는 Frisby JS에서 어린이 테스트가 무시되었습니다.

채팅 앱에서 토론 삭제를 테스트하고 싶습니다. 이를 위해 채팅에서 새로운 토론을 만들고 토론에 메시지를 추가해야합니다.

두 번째 .then() 메소드 다음에 넣으면 내 테스트가 실패한 것으로 나타났습니다. 세 번째 .then() 후에도 실패합니다. 그러나 첫 번째 .then() 메서드 다음에 올바르게 작동합니다.

명시 적 테스트가 실패한 예제 코드 expect (false) .toBe (true); : 나는 검사를 실행할 경우

var frisby = require('frisby'); 
describe("chat update", function() { 
    it("message added", function(done) { 
    frisby.post('http://localhost:3000/api/chat', { 
     name: "remove" 
    }) 
    .then(function (res) { 
     let id = res._body.id; 
     expect(false).toBe(true); // (1) it fails the test 
     frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage', 
     { 
      auteur: "Samuel", 
      message: "My message" 
     } 
    ) 
     .then(function (res) { 
     expect(false).toBe(true); // (2) Without (1) it's ignored by frisby 
     frisby.post('http://localhost:3000/api/chat/remove', 
      {id: id} 
     ) 
     .then(function (res) { 
      expect(false).toBe(true); // (3) Without (1) it's ignored by frisby 
     }) 
     }); 
    }) 
    .done(done); 
    }) 
}); 

, 그것은 기대 (false)를 .toBe (참) 덕분에 실패; // (1) 테스트를 통과하지 못했습니다. 라인. 이 줄을 제거하면 테스트가 실행되고 jasmine이이 줄을 올바른 것으로 유효하게 만듭니다.

(2) 및 (3) 테스트를 무시하지 않는 방법을 알고 있습니까?

+0

이전 버전의 Frisby 또는 최신 버전을 사용하고 있습니까? "오래된"버전은 jasmine-node를 사용했고 새로운 버전은 Jest를 사용하기 때문에 나는 묻는다. –

+0

나는 더 새로운 것을 사용한다. 해결책을 찾았고 대답으로 답했습니다. 나는 반환 조작원을 잊었다. 감사. – jedema

답변

1

마지막으로 해결책을 찾았습니다. 나는 다음과 같은 코드에서 같은 리턴 (첫 번째 제외) 모든 frisby 행동에 잊었 때문입니다 :

var frisby = require('frisby'); 
describe("chat update", function() { 
    it("message added", function(done) { 
    frisby.post('http://localhost:3000/api/chat', { 
     name: "remove" 
    }) 
    .then(function (res) { 
     let id = res._body.id; 
     return frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage', 
     { 
      auteur: "Samuel", 
      message: "My message" 
     } 
    ) 
     .then(function (res) { 
     return frisby.post('http://localhost:3000/api/chat/remove', 
      {id: id} 
     ) 
     .then(function (res) { 
      expect(false).toBe(true); // Will fail the test 
     }) 
     }); 
    }) 
    .done(done); 
    }) 
}); 

당신은 frisby.post() 전에 반환 연산자를 알 수 있습니다. 도움이되기를 바랍니다.