Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xenobytezero opened this issue Nov 28, 2024 · 0 comments

Comments

@xenobytezero
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant