I am writing a node.js app in coffee-script using the express framework. After exploring a couple of options I finally decided to use mocha and zombie.js. However, I am having a hard testing the UI. For example, to implement a successful user authentication I do the following: see the code pasted here my_gist
What I really wanted to do is the following:
- call
get '/sessions/new'
, which will call the SessionsController and display the authentication form - then I'll call the
browser.visit
method, enter the values for the fields and submit the form, which will generate a post method if the username and password are correct, I'll expect the SessionsController to react accordingly and redirect to the right page. Unfortunately, whenever I run the tests it complains about
Zombie: require is not defined ReferenceError: require is not defined
. It turns out it doesn't like the two lines in my /javascripts/app.jsrequire("coffee-script") require('./tfs.coffee')
Even when I try to extract any information from the browser after the visit method, I just get undefined values. Apparently none of my assertions is being tested. It just passes the test. Is there anything I am doing wrong? Has anyone testing coffee-script written app in express using Zombie.js faced that problem? what could be the fix?
If /javascripts/app.js is being loaded from the browser, you would want to make sure that RequireJS (or some other browser framework that defines
require
) is loaded first, or load them in your HTML document:<script src="coffee-script.js" type="text/javascript"></script>
<script src="tfs.coffee" type="text/coffee"></script>
You might need to wait until the page is fully loaded before extracting values.