2016-04-29 94 views
0

我正在为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

我不知道如何进行单元测试 –

+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(){ 

    });   

});