小编Gur*_*noy的帖子

将 JSON 对象转换为响应对象

我正在尝试将模拟 JSON 数据传递到我的 jasmine 单元测试中。

我的 JSON 格式如下所示:

{   
   "CompanyResponse":{    
      "CompanyCreatedDate":"1990-10-02",    
      "RunDate":"2",   
      "LastChangedDate":"2015-10-02",   
      "CompanySummary": {   
         "Id":"Apple",   
         "MaximumCredit":"10000000",   
         "Margin":"60000000",    
         "Limit":"-1500000",    
         "HistoricData":{    
            "CompanyHistoricData": [   
               {  
                  "LaunchDate":"2008-08-31",  
                  "Product":"Iphone2",  
                  "TotalProductsCreated":"1000000",  
                  "TotalProductsSold":"800000",  
                  "TotalReturns":"200000",  
                  "TotalMargin":"600000"  
               },  
               {  
                  "LaunchDate":"2010-08-31",  
                  "Product":"Iphone4",  
                  "TotalProductsCreated":"2000000",  
                  "TotalProductsSold":"1500000",  
                  "TotalReturns":"350000",  
                  "TotalMargin":"800000"  
               }  
            ]  
         },  
         "RefurbishedData": {  
            "CompanyRefurbished": [  
               {  
                  "Id":"Apple.201221.12",  
                  "ProductId":"iph-213454",  
                  "StartDate":"2015-09-07",  
                  "FinishDate":"2015-09-10",  
                  "CostOfRefurbishing":"50"  
               },  
               {  
                  "Id":"Apple.201228.12",  
                  "ProductId":"iph-4155655",  
                  "StartDate":"2015-09-10",    
                  "FinishDate":"2015-09-12",  
                  "CostOfRefurbishing":"85"  
               }  
            ]  
         }  
      }  
   }  
}  
Run Code Online (Sandbox Code Playgroud)

我正在使用上面的 JSON 传递一个类似于下面的函数进行单元测试:

public getTotal(response: CompanyResponse): void {    
  var companySummary = response.CompanySummary;    
  
  //gets total 'CostOfRefurbishing' for all …
Run Code Online (Sandbox Code Playgroud)

javascript json jasmine aurelia

3
推荐指数
1
解决办法
6238
查看次数

标签 统计

aurelia ×1

jasmine ×1

javascript ×1

json ×1