Title: Default value (object of type Proxy) can give false positives when testing validations · Issue #165 · ffMathy/FluffySpoon.JavaScript.Testing.Faking · GitHub
Open Graph Title: Default value (object of type Proxy) can give false positives when testing validations · Issue #165 · ffMathy/FluffySpoon.JavaScript.Testing.Faking
X Title: Default value (object of type Proxy) can give false positives when testing validations · Issue #165 · ffMathy/FluffySpoon.JavaScript.Testing.Faking
Description: Hi, Thanks for an amazing lib! It definitely makes work with JavaScript more human-friendly! :) I've bumped into a small difference with NSubstitute behaviour and wondering if maybe I just can't find a proper syntax to turn on or off a s...
Open Graph Description: Hi, Thanks for an amazing lib! It definitely makes work with JavaScript more human-friendly! :) I've bumped into a small difference with NSubstitute behaviour and wondering if maybe I just can't fi...
X Description: Hi, Thanks for an amazing lib! It definitely makes work with JavaScript more human-friendly! :) I've bumped into a small difference with NSubstitute behaviour and wondering if maybe I just can&...
Opengraph URL: https://github.com/ffMathy/FluffySpoon.JavaScript.Testing.Faking/issues/165
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Default value (object of type Proxy) can give false positives when testing validations","articleBody":"Hi,\r\nThanks for an amazing lib! It definitely makes work with JavaScript more human-friendly! :)\r\nI've bumped into a small difference with NSubstitute behaviour and wondering if maybe I just can't find a proper syntax to turn on or off a setting to make things work similarly to what I used to in C#:)\r\n\r\nSo what I'm trying to achieve.\r\nI have an interface\r\n```\r\ninterface Worker {\r\n SUPPORTED_WORK: number[];\r\n doSomething();\r\n}\r\n```\r\n\r\nAnd this kind of usage of the interface in some service:\r\n```\r\nconstructor (private worker: Worker) {}\r\n....\r\n\r\npublic someServiceMethod(workId) {\r\n if (!this.worker.SUPPORTED_WORK.includes(workId)) {\r\n throw Error(\"Invalid work\");\r\n }\r\n...\r\n```\r\n\r\nCurrently, when I setup a test to cover this validation, if I don't specifying any behaviour for `SUPPORTED_WORK` property, the test automatically passes.\r\n```\r\nconst worker = Substitute.for\u003cWorker\u003e();\r\nconst service = new MyService(worker);\r\n\r\nservice.someServiceMethod(42);\r\n...//some test logic\r\n```\r\n\r\nBasing on the NSubstitute behaviour, I would expect this usage to throw an error, since the `SUPPORTED_WORK` property is missing or `.include` behaviour returns null or something like that by default.\r\n\r\nAt the moment, if the mock is unset `.include(workId)` returns a Proxy object, which is truthy. It makes the if-statement pass and giving a false positive in my test.\r\nEven if I wrap this check into some method like:\r\n```\r\n if (!this.worker.isWorkSupported(workId)) {\r\n throw Error(\"Invalid work\");\r\n }\r\n```\r\nThe issue remains.\r\n\r\nWondering, if I can just tweak some setting to prevent false positives in that kind of checks when I miss to setup returns of my mock?","author":{"url":"https://github.com/SergiiVolodkoWorking","@type":"Person","name":"SergiiVolodkoWorking"},"datePublished":"2021-01-13T20:54:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/165/FluffySpoon.JavaScript.Testing.Faking/issues/165"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8986868d-5b69-93a1-c9d8-59b6c9029351 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D0AE:49739:59FA59:75D20B:6980113C |
| html-safe-nonce | fa826cde5b8d171f771b557382db08d410acd0d4e5b512bc4c002464757bfad4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEFFOjQ5NzM5OjU5RkE1OTo3NUQyMEI6Njk4MDExM0MiLCJ2aXNpdG9yX2lkIjoiNDQ3MTczNTI1ODE4MTUzODEwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 88afbc96c7e29cd6e7228cda1186893e008425e39007fae9262a97e0938f07c2 |
| hovercard-subject-tag | issue:785450267 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/ffMathy/FluffySpoon.JavaScript.Testing.Faking/165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f13bac866dc814c1ac76d3141899828d89ec79d0f6415355b849e61e4dfcea97/ffMathy/FluffySpoon.JavaScript.Testing.Faking/issues/165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f13bac866dc814c1ac76d3141899828d89ec79d0f6415355b849e61e4dfcea97/ffMathy/FluffySpoon.JavaScript.Testing.Faking/issues/165 |
| og:image:alt | Hi, Thanks for an amazing lib! It definitely makes work with JavaScript more human-friendly! :) I've bumped into a small difference with NSubstitute behaviour and wondering if maybe I just can't fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SergiiVolodkoWorking |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/ffMathy/FluffySpoon.JavaScript.Testing.Faking git https://github.com/ffMathy/FluffySpoon.JavaScript.Testing.Faking.git |
| octolytics-dimension-user_id | 2824010 |
| octolytics-dimension-user_login | ffMathy |
| octolytics-dimension-repository_id | 139153585 |
| octolytics-dimension-repository_nwo | ffMathy/FluffySpoon.JavaScript.Testing.Faking |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 139153585 |
| octolytics-dimension-repository_network_root_nwo | ffMathy/FluffySpoon.JavaScript.Testing.Faking |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width