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

Quality Assurance Intermediate Selenium WebDriver Use Selenium with Testing Frameworks Selenium and Mocha

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I'm lost. Mocha command isn't working

I'll be honest from the start in that although I'd taken the JavaScript Unit Testing course I wasn't very successful with it, but I do have some idea at least of how to run tests in this course.

I believe I've set up all the packages I need to, to follow along.

    npm install selenium-webdriver
    npm install -g mocha
    npm install -g chromedriver
    npm install -g geckodriver

I downloaded the course files but am I right in thinking I need to use a separate directory to save the invitees.js file to for this video? I've done that, and have a separate directory. I've added the test directory and the invitees file to it but the mocha command does not work.

$ mocha 
Warning: Could not find any test files matching pattern: test
No test files found

Help! :)

// Run `node`, demo `require("selenium-webdriver")`
const {Browser, By, Key, until} = require("selenium-webdriver");
const {suite} = require("selenium-webdriver/testing");
const assert = require('assert');

//connect to URL or "localhost"
const url = "https://treehouse-projects.github.io/selenium-webdriver-intermediate/waits/app/index.html";

suite(function(env) {
    describe('RSVP site', function() {
        it('has invitee list', function() {
        env.builder().build().then(driver => {
                .then(() => driver.findElements(By.id('invitedList')))
                .then(elements => assert(elements.length > 0))
                .then(() => driver.quit());


6 Answers

Hi Jonathan Grieve, I was able to get the mocha command to work when I went through the exercise, and your code looks the same as mine.

  • Is your invitees.js file inside a folder/directory named 'test'?
  • When I use npm install on Windows 10 (which I believe you are using), I no longer use Git Bash. I use the built in Windows command prompt, and I right-click on it in the start menu so I can run it as an Administrator. That gives me less errors during installs. The mocha command works for Chrome, but for some reason it doesn't recognize the Firefox/gecko driver. Let me know if that helps.
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

It's working!

It's weird though. I've just tested mocha in VS Code's integrated terminal and it's run the test successfully.

I've just done the same with the Git Bash standalone executable. Same result.

I'm sure, even now, I tested the mocha command inside the correct directory (I made an s1v3 directory) and the test pattern simply was never recognised. Seems like I need to get my head tested as well as selenium. ??

Ihor Khrystiuk
Ihor Khrystiuk
1,643 Points

If you type the mocha command on Windows(in my case it is a VS Code and git bash terminal) and it seems not working, you code should be like this one:

const { Browser, By, Key, until } = require("selenium-webdriver");
const assert = require("assert");

describe("RSVP site", function() {
  it("has invitee list", function() {
    assert(1 === 1);

Whatever makes it work, that's all that matters. :) Glad you are able to move forward now.

Also, if testing in chrome add require("chromedriver"); to the top of the space. I was having issues with env not defined and mocha saying tests are failing. adding require("chromedriver"); to the top resolved those issues.

require("chromedriver"); const {Browser, By, Key, until} = require("selenium-webdriver"); const {suite} = require("selenium-webdriver/testing"); const assert = require('assert');

Willy Tedyanto
Willy Tedyanto
2,597 Points

You should run mocha command from the parent directory of test directory.

I believe you have run mocha inside test directory.

Jacob Eliasson
Jacob Eliasson
3,730 Points

I can't get the mocha command to work. Whenever I run it in the Terminal, a text just appears with "Error: No test files found". my location in the CLI is project, the name of the folder that I created the test-folder in, which holds my JS file.

Is there any easy fix to this or is there something I have missed here?

Tried running it both in Macs terminal window and VS Code Terminal