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 Challenge: Expanding Our Expectations

Sergi Oca
Sergi Oca
7,981 Points

document is not defined when running mocha.

I have uploaded my own files to a workspace and I'm getting and on my first line:

.document.getElementById("submit").addEventListener ...

Im getting:

ReferenceError: document is not defined.

If I try to add window. before document I get that window is not defined. Any ideas?

2 Answers

Steven Parker
Steven Parker
231,248 Points

Are you running this on your browser, or using node.js?

There's no window (or document) when running under node.js.

If that's not it, try making a snapshot of your workspace and provide the link to it here to enable a more specific and complete analysis.

Sergi Oca
Sergi Oca
7,981 Points

Well I'm running it in a workspace, using commands. Hmmm, well that's not really explained in this course so far.

Steven Parker
Steven Parker
231,248 Points

The objects "window" and "document" would only be available inside your browser. If you are editing scripts in your workspace and have used the preview to launch a browser to view the results in, you should have access to these.

But if you are running commands in the workspace console, directly or indirectly using node.js, these would not exist.

Sergi Oca
Sergi Oca
7,981 Points

Makes perfect sense now, thank you Steven.