jest とネストを使用して単体テスト ケースを作成しようとしていますが、次のエラーが発生します。
DeviceSecretService › should call createCredentials method with expected parms
Cannot spyOn on a primitive value; undefined given
23 | // });
24 | it('should call createCredentials method with expected parms', async () => {
> 25 | const createCredentialsSpy = jest.spyOn(service, 'createCredentials');
| ^
26 | const deviceId = 'deviceId';
27 | const dci = new DeviceCommunicationInterface();
at Object.<anonymous> (device/services/device-secret/device-secret.service.spec.ts:25:39)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 20.61 s, estimated 76 s
Ran all test suites matching /device-secret.service.spec.ts/i.
npm ERR! Test failed. See above for more details.
以下は、spec.ts ファイルのコードです。
it('should call createCredentials method with expected parms', async () => {
const createCredentialsSpy = jest.spyOn(service, 'createCredentials');
const deviceId = 'deviceId';
const dci = new DeviceCommunicationInterface();
service.createCredentials(deviceId,dci);
expect(createCredentialsSpy).toHaveBeenCalledWith(deviceId,dci);
});
});
私はすべてを試しましたいくつかの提案をお願いします