我在下面有一个常量类。当我尝试使用spyOn返回一个不同的值以测试错误情况时,ng测试返回类型为'"retryCount"' is not assignable to parameter of type 'never'.‘的编译时错误参数
有没有办法绕过这个问题?
export class NConstants {
public static retryCount: number = 2;
public static readonly retryDelayInMilliseconds: number = 10000; // ms
public static readonly retryNotificationDelayInSeconds: number = 50;
}
spyOn(NetworkConstants, 'retryCount').and.returnValue(0);所有包
"jasmine-auto-spies": "^4.1.0",
"jasmine-core": "~3.3.0",
"jasmine-marbles": "^0.6.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.1.3",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "^2.0.0",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-trx-reporter": "^0.3.0",发布于 2021-02-19 08:34:36
您只能对类的方法/函数执行spyOn操作,而不能对实例变量执行操作。
要将其更改为返回0,只需直接修改即可。
NConstants.retryCount = 0;
// do what you want.
// further down the line, you can reset it
NConstants.retryCounter = 2;https://stackoverflow.com/questions/66270154
复制相似问题