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 trialJason Sera
Front End Web Development Techdegree Graduate 17,595 PointsAm I using the correct test of "to.have.all.keys" to match for the correct properties? Its says failed test still pass
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');
})
})
function clone (objectForCloning) {
return Object.assign({}, objectForCloning)
}
module.exports = clone
1 Answer
Steven Parker
231,275 PointsHaving 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.
You may want to report that last issue to the Support folks.
Jason Sera
Front End Web Development Techdegree Graduate 17,595 PointsJason Sera
Front End Web Development Techdegree Graduate 17,595 PointsSo 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 () {
})
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
231,275 PointsSteven Parker
231,275 PointsIt looks line one of the provided code lines got changed above where you were you were to put your work:
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
Front End Web Development Techdegree Graduate 17,595 PointsJason Sera
Front End Web Development Techdegree Graduate 17,595 PointsOmg! 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!