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 trial

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

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

I'm not quite getting the answer to this code challenge. I think the problem is after ".to.have.property({});". Error message: "Version of clone.js DOESN'T work correctly, test expected to fail, but spec passes," or "version of clone.js works correctly, but spec doesn't pass." I've done numerous arrangements of the expectation with either of these error messages. I'm not sure any arrangement passes through clone.js correctly. Everything I've tried is an incorrect answer.

clone_spec.js
var expect = require('chai').expect

describe('clone', function () {
    var clone = require('./clone.js')
    it('should return an object where all properties match', function () {

        expect(clone).to.deep.equal.all.property;

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

module.exports = clone
Are Arntsen
Are Arntsen
11,035 Points

Hi!

I also struggled with this one. I skipped it and found the answer later in the course. This should work:

var expect = require('chai').expect

describe('clone', function () {
    var clone = require('./clone.js')
    it('should return an object where all properties match', function () {
        expect(clone({ foo: 'bar' })).to.eql({ foo: 'bar' });
    })
})

1 Answer

Are Arnsten:

That's a direct copy from the Chai Assertion Library, but I don't think that's what the instructor was looking for.

Here's the result: "We tried your spec with a version of clone.js that DOESN'T work correctly, expecting test to fail, but it passed.” It's a "Bummer!" statement which means the answer isn't correct & therefore, I can't pass the test question.

Are Arntsen
Are Arntsen
11,035 Points

It is almost a direct copy of the Chai Assertion library. You need to put the example object in to the "clone" function. When I do this challenge it passes with the exact syntax as my previous answer. ItΒ΄s strange that it does not work for you no?

Sebastian Karg
Sebastian Karg
28,705 Points

Had trouble with this one as well. Tried the above answer and got a bummer too, but found out that I used "to.equal" instead of "to.eql". After fixing this, the test passed.