2016-09-13 4 views
0

현재 프론트 엔드 응용 프로그램의 기능/동작 테스트를 수행하는 데 "Intern.js"를 사용하고 있습니다 (버튼 클릭, 팝업 메시지 예상 등). 에).Javascript : 이미 정의 된 형식에 메서드를 연결하는 방법

간단한 테스트가 될 것 같은 뭔가 :

bdd.describe('###### txtFirstName', function() { 
    bdd.it('must be a "text" type input', function() { 
    /** Begin the test */ 
    let test = 

     /** Find the 'addUserModal' on the DOM and then find the 'txtFirstName' inside it */ 
     helper.addUserModal.find.field.txtFirstName() 
     .getProperty('type') 
     .then(function(type) { 
      expect(type).to.equal('text'); 
     }) 
     .end() 
    /** End the test */ 
    .end(); 

    return test; 
    }); 
}); 

참고 시험의이 부분 :

.getProperty('type') 
.then(function(type) { 
    expect(type).to.equal('text'); 
}) 
.end() 

모달의 모든 입력을 반복, 그래서 대신에 그것을 반복 될 것이다 모든 테스트, 나는 같은 것을하고 싶었다 :

/** Begin the test */ 
let test = 
    /** Find the 'addUserModal' on the DOM and then find the 'txtFirstName' inside it */ 
    helper.addUserModal.find.field.txtFirstName() 
    .must.be.a.text.input() 
/** End the test */ 
.end(); 

그리고 "must.be.a.text.input()"은 전자 형식 어설 션.

주목해야 할 중요한 점은 모든 "Intern.js"메소드가 Promise를 반환한다는 것입니다.

의견이 있으십니까?

감사합니다.

은 "Intern.js"LIB : https://theintern.github.io/

그것은 문서입니다 : 당신은 chai-as-promised를 사용하려고 할 수 있습니다 https://theintern.github.io/leadfoot/module-leadfoot_Command.html

답변

0

. 와

차이로써의 약속,

expect(helper.addUserModal.find.field.txtFirstName().getProperty('type')) 
    .to.eventually.equal('text') 
과 같이 쓸 수있다

helper.addUserModal.find.field.txtFirstName() 
    .getProperty('type') 
    .then(function(type) { 
     expect(type).to.equal('text'); 
    }) 

코드