(Answer in coffeescript. If you'd like to convert coffee to js use http://coffeescript.org/, then the Try CoffeeScript tab.)
If you're testing asynch code you'll need to use the
describe "User", -> describe "#save()", -> it "should save without error", (done) -> user = new User("Luna") user.save done
http://visionmedia.github.io/mocha/ under "Asynchronous code". Looks like createJob is returning true because the test is zipping through the code to send the post etc. and saying "yep, I sent all that stuff like you asked!".
I'd recommend Martin Fowler's article on testing asynch js code with mocha: http://martinfowler.com/articles/asyncJS.html.
I've got a chunk of code that tests retrieval of a user from the database (using sinon for stubbing). The real code connects to the db then calls the onSuccess with the user's configuration:
describe 'Config', -> orgId = 'a' errorHandler = ((msg) -> (throw msg)) beforeEach -> readConfig = sinon.stub(sdl , 'getConfig') readConfig.callsArgOnWithAsync(2, configSource, JSON.parse(jsonConfig)) afterEach -> configSource.getConfig.restore()
configSource.getConfig('520bc323de4b6f7845543288', errorHandler, (config) -> config.should.not.be.null config.should.have.property('preferences') done() )