Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 消除角函数的副作用_Javascript_Angular_Unit Testing_Typescript_Side Effects - Fatal编程技术网

Javascript 消除角函数的副作用

Javascript 消除角函数的副作用,javascript,angular,unit-testing,typescript,side-effects,Javascript,Angular,Unit Testing,Typescript,Side Effects,我正在制作一个接收两个参数的方法,选项和数据,但是在返回值中只返回选项,我想在这个项目上实施单元测试,我想避免这个方法的副作用,我想知道这是最好的方法,返回一个数组,每个数组有两个值,或者将此方法拆分为两个返回不同值的小方法 这是我简化的演示方法: private setEst(data, options): object { const numCols: number = data.getColNumber(); const indxRows: Array<Nu

我正在制作一个接收两个参数的方法,
选项
数据
,但是在返回值中只返回
选项
,我想在这个项目上实施单元测试,我想避免这个方法的副作用,我想知道这是最好的方法,返回一个数组,每个数组有两个值,或者将此方法拆分为两个返回不同值的小方法

这是我简化的演示方法:

private setEst(data, options): object {

    const numCols: number = data.getColNumber();    
    const indxRows: Array<Number> = data.getIndexRows();
    const otherArray: : object[] = [];

    // Creating options output that will be returned
    for (let col = 1; col < numCols; col++) {
        // Do something with options to modify the value of this param
        ...

        // Read data to create an array that will be used by the next process
        otherArray.push({
          id: data(col).getId();
        });
      }
    }

    // Output data as a side effect
    indxRows.forEach(indx => {
      for (let col = 1; col < numCols; col++) {

        // Do something with data object and otherArray const, 
        // data is modified and returned as side effect...
        ...


      }
    });

    return options;
}
private setEst(数据、选项):对象{
const numCols:number=data.getColNumber();
const indxRows:Array=data.getIndexRows();
常量otherArray::对象[]=[];
//创建将返回的选项输出
for(设col=1;col{
for(设col=1;col