Jasmine测试打字稿中对象的实例化

时间:2016-04-29 13:47:28

标签: typescript angular jasmine

我正在为Angular2项目编写单元测试,我在测试类似下面的内容时遇到了问题。期望创建头对象,并使用正确的参数调用append方法。有一个简单的方法吗?

myFunction ( ){

    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded' );

}

我需要完成

describe('myFunction', function() {

    it('should create headers object', function(){

    });
    it('should call append in headers object with name and value', function(){

    });        

});

1 个答案:

答案 0 :(得分:1)

myFunction ( ){

    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded' );
    return headers;
}
describe('myFunction', function() {

    it('should create headers object', function(){
      let headers = myFunction();
      headers.forEach((values: string[], name: string, headers: Map<string, string[]>) => {
        // do check with each passed header
      });
    });
    it('should call append in headers object with name and value', function(){

    });        

});