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

Trying to create 'numerical keys' for an array using .then method is not working #84

Open
lavanyaac opened this issue Apr 18, 2018 · 2 comments
Labels

Comments

@lavanyaac
Copy link

Issue:

I'm trying to create a non-numerical keys for the array and it is not working on the latest master(build on 04-14-2018 - testcheck@^1.0.0-rc.2). Seems like it used to work for the old code that is published to npm.

Working Example on the console of 'http://leebyron.com/testcheck-js ':

const arr = gen.array(gen.int,{size:10})

const oneMoreArr = arr.then(val => {
val['foo'] = ()=> console.log('Hello')
return val;
});
sampleOne(oneMoreArr2)
sampleOne(oneMoreArr2).foo();

Output:

sampleOne(oneMoreArr2)

[7, 3, 29, 10, 16, -29, 4, -14, 23, 19, foo: ƒ]

sampleOne(oneMoreArr2).foo();

Hello
=====================================================================
For the same code output on the master build from 04-14-2018 (testcheck@^1.0.0-rc.2)


sampleOne(oneMoreArr2)

[[ 18, -29, -28, 27, -14, -11, -3, -16, -27, -10 ] - (missing key 'foo')

sampleOne(oneMoreArr2).foo();

undefined - (expected hello to be logged)

@leebyron leebyron added the bug label Apr 19, 2018
@leebyron
Copy link
Owner

Thanks for reporting this! This seems like a bug since the master build now clones values returned from .then() to avoid mutation cross-affecting tests, and the clone behavior for Arrays only includes array indices and doesn't consider non-numeric keys.

You should be able to work around this in the meantime by changing return val; to return gen.return(val);

@lavanyaac
Copy link
Author

Thanks for the work around.

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

No branches or pull requests

2 participants