Skip to content

Null parameter in function call which fails a verify does not produce a useful error message #65

@xenobytezero

Description

@xenobytezero

Example

https://stackblitz.com/edit/vitest-dev-vitest-qg1hxb?file=test%2Fbasic.test.ts

If a function call is made on a Mock which takes a null parameter, which is then verified and fails, it produces a non-useful error message.

TypeError: Cannot read properties of null (reading 'hasOwnProperty')
 ❯ MethodCallToStringConverter.objectIsStringable node_modules/@typestrong/ts-mockito/lib/utils/MethodCallToStringConverter.js:21:47
 ❯ eval node_modules/@typestrong/ts-mockito/lib/utils/MethodCallToStringConverter.js:16:68
 ❯ eval node_modules/@typestrong/ts-mockito/lib/utils/MethodCallToStringConverter.js:16:34
 ❯ MethodCallToStringConverter.convertActualCalls node_modules/@typestrong/ts-mockito/lib/utils/MethodCallToStringConverter.js:14:22
 ❯ MethodStubVerificator.actualCalls node_modules/@typestrong/ts-mockito/lib/MethodStubVerificator.js:91:76
 ❯ MethodStubVerificator.times node_modules/@typestrong/ts-mockito/lib/MethodStubVerificator.js:30:62
 ❯ MethodStubVerificator.once node_modules/@typestrong/ts-mockito/lib/MethodStubVerificator.js:17:14

It looks like objectIsStringable() in src/utils/MethodCallToStringConverter.ts can't handle null values (including I assume undefined), since it tries to do arg.hasOwnProperty("toString"); if the arg is not an Object, which will immediately fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions