如何使用模拟的ts-jest / utils模拟通用类型的函数

时间:2020-10-27 10:15:36

标签: typescript unit-testing jestjs mocking ts-jest

我有这样的功能

onChange

,我想模拟Scanner sc = new Scanner(System.in); short n = sc.nextShort(); short a[] = new short[n]; short b[] = new short[n]; for (short i = 0; i < n; i++) {// taking elements input a[i] = sc.nextShort(); } for (short i = 0; i < n; i++) {// taking elements input b[i] = sc.nextShort(); } short m = 0; for (short i = 0; i < n; i++) {// finding smallest element in array 'a' for (short j = 0; j < n; j++) { if (a[i] < a[j]) { m = a[i]; } } } boolean allequal = false; while (!allequal) { for (short i = 0; i < n; i++) {// subtracting elements if (a[i] == m) continue; if (a[i] >= b[i]) { a[i] -= b[i]; } } for (short i = 0; i < n; i++) { for (short j = 0; j < n; j++) { if (a[i] == a[j]) { allequal = true; } else { allequal = false; } } } } for (int i = 0; i < n; i++) {// printing array 'a' System.out.print(a[i] + " "); } 5 5 7 10 5 15 2 2 1 3 5 5 5 9 5 10 函数 我这样尝试

const myOtherMethod = (param1: any) => {
  // return some code
}

export const myFunc = <T>(param1: any): T => {
  const value: T = myOtherMethod(param1);
  return value;
}

或这样

myFunc

但不起作用。有任何想法吗?

0 个答案:

没有答案