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 Introducing Unit Testing Running an Automated Test

what is wrong about my code?

const Mocha = require('mocha'); const fs = require('fs'); const path = require('path');

// Create a new Mocha instance const mocha = new Mocha();

// Add your test file to the Mocha instance const testFilePath = path.join(__dirname, 'tests.js'); mocha.addFile(testFilePath);

// Run the tests mocha.run(function(failures) { process.exitCode = failures ? 1 : 0; // Exit with non-zero status if there are failures });

1 Answer

Rachel Johnson
STAFF
Rachel Johnson
Treehouse Teacher

Hey Sun Toth , thanks for your post!

The code challenge attached to this question is this one: https://teamtreehouse.com/library/javascript-unit-testing/introducing-unit-testing/running-an-automated-test, so I will be answering your question with this as the code challenge of inquiry

The code that you provided in this forum post looks like it's Javascript code. However, the code challenge is to provide a command to use mocha to run all the tests that was already written in the tests.js Javascript file.

This means that all the Javascript was already written in the test.js file mentioned in the question, and your job for this code challenge is simply to use mocha to run it.

In 1:20 of the video preceding this code challenge Running Your First Automated Test we can see Guil run mocha test in the console. We can take this and do a similar thing:

mocha tests.js

I hope this helps!