You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started playing with K6 for Smoke Testing purposes, and I am facing some issues with my internal utils that leverage Object.prototype.hasOwnProperty.call() to perform some assertions in my workflow on the res.json() HTTP response data structure, whom I believe doesn't work as expected.
Object.prototype.hasOwnProperty.call( jsonResponse, 'length' ) to be true.
Actual Behavior
Object.prototype.hasOwnProperty.call( jsonResponse, 'length' ) is false.
Steps to Reproduce the Problem
Use the following simplified snippet that re-uses the official example's crocodiles API
importhttpfrom'k6/http';import{check,sleep,fail}from'k6';consthasLength=(value: unknown): boolean=>Object.prototype.hasOwnProperty.call(value,'length')&&(valueasany).length>0;constisArrayFull=(value: unknown): value is unknown[]=>Array.isArray(value)&&hasLength(value);exportdefaultfunctionmain(): void{constbaseArray=['foo','bar','baz',];constres=http.get('https://test-api.k6.io/public/crocodiles/');constcrocs=res.json();check(res,{'is status 200': (r)=>r.status===200,// Always fails even when the requests is successful'has crocodiles info': ()=>isArrayFull(crocs),});// Dummy cond to get rid of TS errors and to avoid non-null assertion operatorif(!crocs)fail('no croc found');// Dummy console log to reproduce:// 1. baseArray reference properly constructedconsole.log('baseArray Object.prototype.hasOwnProperty.call',Object.prototype.hasOwnProperty.call(baseArray,'length'));console.log('baseArray hasOwnProperty (not recommended due to eventual DOS):',baseArray.hasOwnProperty('length'));console.log('baseArray is array:',Array.isArray(baseArray));console.log('baseArray length:',baseArray.length);// 2. response array built from res.json()console.log('crocs Object.prototype.hasOwnProperty.call',Object.prototype.hasOwnProperty.call(crocs,'length'));console.log('crocs hasOwnProperty (not recommended due to eventual DOS):',crocs.hasOwnProperty('length'));console.log('crocs is array:',Array.isArray(crocs));console.log('crocs length:',crocs.length);sleep(1);}
Run the script without any specific parameters (do not forget to transpile as it's typescript code)
k6 run ./k6-issue/dist/has-own-prop.test.ts.
Confirm that the API's response result is fasle (crocs Object.prototype.hasOwnProperty.call false) despite the fact that the property length exists, while the baseArray reference is true (baseArray Object.prototype.hasOwnProperty.call true)
3.1. Confirm that the has crocodiles info check also fails
...
INFO[0001] baseArray Object.prototype.hasOwnProperty.call true source=console
INFO[0001] baseArray hasOwnProperty (not recommended due to eventual DOS): true source=console
INFO[0001] baseArray is array: true source=console
INFO[0001] baseArray length: 3 source=console
INFO[0001] crocs Object.prototype.hasOwnProperty.call false source=console
INFO[0001] crocs hasOwnProperty (not recommended due to eventual DOS): false source=console
INFO[0001] crocs is array: true source=console
INFO[0001] crocs length: 8 source=console
running (00m01.5s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m01.5s/10m0s 1/1 iters, 1 per VU
✓ is status 200
✗ has crocodiles info
↳ 0% — ✓ 0 / ✗ 1
...
Please let me know if you need any additional information.
Thanks.
The text was updated successfully, but these errors were encountered:
This seemed to have been broken since v0.28.0 and even before that (IMO) it was working because it was hitting the one case it worked in, but with #2135 it should work again 🤞
This seemed to have been broken since v0.28.0 and even before that (IMO) it was working because it was hitting the one case it worked in, but with #2135 it should work again 🤞
I confirm that it works with the freshly released v0.34.1 (2021-09-16T08:24:44+0000/0628db0, go1.16.8, linux/amd64) that includes #2135 changeset.
Greetings,
I started playing with K6 for Smoke Testing purposes, and I am facing some issues with my internal utils that leverage
Object.prototype.hasOwnProperty.call()
to perform some assertions in my workflow on theres.json()
HTTP response data structure, whom I believe doesn't work as expected.Environment
k6 v0.33.0 (2021-06-29T10:38:31+0000/cc0361c, go1.16.5, linux/amd64)
Expected Behavior
Object.prototype.hasOwnProperty.call( jsonResponse, 'length' )
to betrue
.Actual Behavior
Object.prototype.hasOwnProperty.call( jsonResponse, 'length' )
isfalse
.Steps to Reproduce the Problem
3.1. Confirm that the
has crocodiles info
check also failsPlease let me know if you need any additional information.
Thanks.
The text was updated successfully, but these errors were encountered: