Reactjs 开玩笑地模拟和测试函数

Reactjs 开玩笑地模拟和测试函数,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我在helper.ts文件中有以下函数 export public myFunction = () => { const arr = []; for (let index = 0; index < 5; index++) { arr.push(i); } return arr; } export public myFunction=()=>{ 常数arr=[]; 对于(让索引=0;索引

我在
helper.ts
文件中有以下函数

export public myFunction = () => {
    const arr = [];
    for (let index = 0; index < 5; index++) {
        arr.push(i);
    }

    return arr;
}
export public myFunction=()=>{
常数arr=[];
对于(让索引=0;索引<5;索引++){
arr.push(i);
}
返回arr;
}

我如何在我的Jest测试中测试它?

给定一个文件
helper.ts

export const myFunction = () => {
  const arr = [];
  for (let index = 0; index < 5; index++) {
      arr.push(index);
  }
  return arr;
}

您需要提供更多的上下文。这是课程的一部分吗
private
是JavaScript中的一种类型,是这种类型的脚本吗?我改变了原来的帖子。这不是在课堂上。它只是一个位于ts文件中的公共函数。您想模拟什么?看起来您只是想测试在调用此函数时是否返回一个大小为5的数组function@ZeroDarkThirty友好提示,如果答案提供您所需的信息,请向上投票并标记为已接受
import { myFunction } from './helper';

describe('myFunction', () => {

  it('should return an array with the numbers 0-4', () => {
    expect(myFunction()).toEqual([0,1,2,3,4]);
  });

});