Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTyler Wanner
4,455 PointsWhere is the object for clone?
If I add one, such as let e={1,2,3}, then expect(clone(e).to.have.same.members(e), fails
var expect = require('chai').expect
describe('clone', function () {
var clone = require('./clone.js')
let e = {1,2,3}
it('some description string', function () {
expect(clone(e)).to.have.same.members(e);
// YOUR CODE HERE
})
})
function clone (objectForCloning) {
return Object.assign({}, objectForCloning)
}
module.exports = clone
2 Answers
Seth Kroger
56,413 PointsThe issue here is that {1,2,3}
isn't a proper object because it's just a list of values, but an object is property-value pairs like { a: 1, b: 2, c: 3 }
There is an property shorthand if you have a variable defined with the same name as the property, so you could do { a, b, c }
if those are defined already. However that only works with variables, not literal values. (Go open the JavaScript console in DevTools and type let e = {1,2,3}
. You'll see it's a Syntax Error.
Seth Kroger
56,413 PointsWell, this was an odd one to figure out. It turns out you need to use var instead of let or the challenge won't pass, even on an otherwise correct answer. (Which is normally deep.equals() not have.same.members(). have.same.deep.members() looks like it should work from the docs, but it doesn't)
Tyler Wanner
4,455 PointsTyler Wanner
4,455 Pointsthanks, I thought everything was an object in js.. apparently have.same.members also doesn't work... there's a "same" in the chai language chains but it's not used anywhere in the docs...
Tyler Wanner
4,455 PointsTyler Wanner
4,455 Pointsi did some more research wrt this answer, thank you for your context. have.same.members is still not the appropriate assertion even in the case of { a: 1, b: 2, c: 3 }. The fact that "include" works is broken, since the question says MATCHES. Terribly worded question to begin with.
I suggest: Write a test spec that creates object obj and proves the clone function in clone.js takes obj and returns a new object where all properties match obj's... or something like that