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

Object.create always returns {} #695

Closed
pandazy opened this issue Jan 27, 2016 · 5 comments
Closed

Object.create always returns {} #695

pandazy opened this issue Jan 27, 2016 · 5 comments

Comments

@pandazy
Copy link

pandazy commented Jan 27, 2016

No matter what is passed into Object.create as its first parameter, it just returns {}, I am not sure if this is designed in purpose, if yes, I wonder if there is a reason and if there is a workaround. Here is a simple example of test case for this

describe('object.create', function(){
   it('should return return Object.create result', function(){
      console.log('\n','result of Object.create() ===>', Object.create({ a:1, b:2}));
   });
});

The running result of the code above may look like this:

Using Jest CLI v0.8.2, jasmine1
Running 1 test suite...
result of Object.create() ===> {}
PASS  __tests__/simple.js (0.264s)
1 test passed (1 total in 1 test suite, run time 0.658s)

Obviously I am expecting it to return { a: 1, b: 2} instead of {}
I would like to appreciate your effort for examining this issue.

@cpojer
Copy link
Member

cpojer commented Jan 27, 2016

can you console.log(Object.create)? Are you overwriting it with your own implementation that is being mocked?

(I'm closing this because it is likely not an issue with jest and more like a question, but happy to reopen if it turns out to be one :) )

@Sebmaster
Copy link
Contributor

This is a peculiarity of console.log, but it works correctly. Object.create attaches the object you provide as the prototype. And console.log doesn't log the prototype, only the own_properties of the object.

See:

> Object.create({a:1})
{}
> Object.create({a:1}).a
1
> x = Object.create({a:1})
{}
> x.b = 2
2
> x
{ b: 2 }
> x.a
1

@cpojer
Copy link
Member

cpojer commented Jan 28, 2016

@Sebmaster thanks for the explanation! I don't normally pass anything other than null to Object.create.

@pandazy
Copy link
Author

pandazy commented Jan 30, 2016

Yes, I confirmed, great thanks for your answer.

On Thu, Jan 28, 2016 at 11:21 AM, Sebastian Mayr notifications@github.com
wrote:

This is a peculiarity of console.log, but it works correctly.
Object.create attaches the object you provide as the prototype. And
console.log doesn't log the prototype, only the own_properties of the
object.

See:

Object.create({a:1})
{}
Object.create({a:1}).a
1
x = Object.create({a:1})
{}
x.b = 2
2
x
{ b: 2 }


Reply to this email directly or view it on GitHub
#695 (comment).

@cpojer cpojer closed this as completed Feb 18, 2016
SimenB pushed a commit that referenced this issue Oct 7, 2018
## Summary

Building on #6950, this adds an e2e test and the requested circus fix.

fixes #6947
closes #695

To Do:
- [x] make sure new tests pass
- [x] clean up circus fix with proper error information
- [x] update CHANGELOG.md

## Test plan

The e2e test is failing and I'm having trouble figuring out why, so I'd like to see if it fails on CI too.
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants