Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Unit Testing Behavior Driven Development with Mocha & Chai A Testing Test!

Where 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

clone_spec.js
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

    })
})
clone.js
function clone (objectForCloning) {
    return Object.assign({}, objectForCloning)
}

module.exports = clone

2 Answers

Seth Kroger
Seth Kroger
56,406 Points

The 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.

thanks, 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...

i 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

Seth Kroger
Seth Kroger
56,406 Points

Well, 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)