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!

Nadine Schermerhorn
Nadine Schermerhorn
2,324 Points

Challenge where you check a functions object against its properties for a match not passing.

I'm having trouble even in the documentation for which method would work to check an object that was cloned against its copy.

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

describe('clone', function () {
    var clone = require('./clone.js')
    it('checks clone object against all properties', function () {

        expect(clone(Object.assign).to.have.all.keys('object');

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

module.exports = clone

1 Answer

Hi Nadine,

There are several ways you could pass this challenge. Here are a couple to consider:

var object =  { prop1: 1, prop2: 2 };
expect(clone(object)).to.deep.equal(object);

This will test that the clone is exactly the same as the original object, including values.

var object = { prop1: 1, prop2: 2 };
expect(clone(object)).to.have.all.keys('prop1', 'prop2');

This one will test that the dummy object will have all of the keys passed in. Both of these examples should work.

Happy coding.
Leslie