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!

Jason Sera
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Sera
Front End Web Development Techdegree Graduate 17,595 Points

Am I using the correct test of "to.have.all.keys" to match for the correct properties? Its says failed test still pass

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

describe('clone', function () {
    var clone = require('./clone.js').clone;
    it('some description string', function () {

        // YOUR CODE HERE
    let player = {
      team: 'lakers',
      league: 'nba'
    };
    let cloneObej = clone(player);
    expect(cloneObej).to.be.a('object');
    expect(cloneObej).to.have.all.keys('team', 'league');
    })
})
clone.js
function clone (objectForCloning) {
    return Object.assign({}, objectForCloning)
}

module.exports = clone

1 Answer

Steven Parker
Steven Parker
231,275 Points

Having the same keys isn't the same thing as having the same values in each key. A more complete test can be done using the deep.equals() method to compare with the original object.

But also ... and you're going to love this ... the JavaScript engine that performs the challenge evaluation is apparently unable to handle the "let" keyword. Use "var" instead like the provided code does.   :see_no_evil:

You may want to report that last issue to the Support folks.

Jason Sera
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Sera
Front End Web Development Techdegree Graduate 17,595 Points

So changing 'let' too 'var' did help with the way the program is run, so that was super helpful. So I changed my unit test to now run like this where it is comparing the player variable to the created clone function:

describe('clone', function () { var clone = require('./clone.js').clone; it('some description string', function () {

    // YOUR CODE HERE

    var player = {
      team: 'lakers',
      league: 'nba'
     };
expect(clone(player)).to.be.a('object');
expect(clone(player)).to.deep.equal(player);
})

})

But when it runs it says that "a working version isn't passing" :/ . Is there something I am missing? I tried running it on my own machine and it says it passes, but it doesn't pass on the code challenge. Thank you again for your help! :)

Steven Parker
Steven Parker
231,275 Points

It looks line one of the provided code lines got changed above where you were you were to put your work:

    var clone = require('./clone.js')        // this is the original challenge line
    var clone = require('./clone.js').clone  // but this is the line shown in your samples

If you put it back to the original condition, your additions will pass.

Also, you don't really need to separately test for an object, since if it's not, the "deep.equals" will catch it.

Jason Sera
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Sera
Front End Web Development Techdegree Graduate 17,595 Points

Omg! that what it was! You are awesome :D ! I thought I had to put that cause that is how it had been showing us. I can't believe I did that. You are absolutely right, once I removed the clone at the end of the require statement then it passed. Wow! thank you so much! I still can't believe I did that, thank you! thank you!