0
내가 노력하고 sinon.js라고하더라도, false를 돌려이 내가 시험에 노력하고 코드 조각입니다 :Sinon.js 스파이 생성자가 처음으로
class ErrorWithStatusCode extends Error{
constructor(code, message, err){
super(message);
this.code = code;
this.error = err;
}
}
export {ErrorWithStatusCode}
는 이것은 err
오류 개체를 포함하더라도, 내 테스트에 실패, 내 테스트 파일
import {ErrorWithStatusCode} from '../../handlers/error.handler';
import chai from 'chai';
import sinon from 'sinon';
const should = chai.should();
const expect = chai.expect;
describe('Error Class',()=>{
it('the contructor function should be called once',()=>{
const spyFunc = sinon.spy(ErrorWithStatusCode, 'constructor');
const err = new ErrorWithStatusCode(500, 'Sorry, some error occurred.', {message: 'Some error'});
console.log(err);
expect(spyFunc.calledOnce).to.be.true;
})
});
입니다하지만.
이 테스트를 달성하기 위해 노력하고 정말로 확실하지? 그냥 조롱 한 기능을 호출했는지 확인하려는 것 같습니다. 생성자를 조롱 할 필요는 없습니다. 그것을 호출하고 반환 된 객체가 매개 변수로 전달 된 속성을 설정했는지 확인하십시오. – Alex