Questions tagged [mocha.js]

Mocha.js is a feature-rich JavaScript test framework running on Node.js and the browser.

Mocha is a feature-rich test framework running on and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.

There is also a (completely separate) "mocha" library for Ruby, which is about mocking for tests. Searches for "mocha" will find both things, so check your results for and to get the one you are looking for!

7879 questions
3
votes
1 answer

Grunt-Mocha-Test BlanketJS Coverage

I'm trying to setup code coverage with with grunt-mocha-test plugin for GruntJS. I have followed this guide, under the section 'Generating Coverage'. However, running grunt produces a coverage.html report that only has coverage for the test files…
iQ.
  • 3,263
  • 5
  • 33
  • 54
3
votes
1 answer

How to use mongoose in mocha unit test?

I feel very confused, how to unit test involves mongodb in mocha, I still can not successfully call the save function with no exception is thrown. I try to use the most simple example for testing and found that there are still problems.Here is my…
elrrrrrrr
  • 796
  • 6
  • 15
3
votes
2 answers

How to test RESTful CRUD api with Mocha Chai on Node.js server side if login needed?

I want to test a web app server side CRUD logics. But only login user can visit the web app. if (res.locals.user){ //CRUD functions here } I know how to use Mocha and Chai to test these CRUD functions without the login check there, but how can…
Russj
  • 649
  • 10
  • 20
3
votes
1 answer

Mocha test runs twice

i'm trying to figure out why this test runs twice: it ( "should verify file exists with a one name filename ", function ( done ){ var fileNameOneChar = "/Users/myusername/t.mp3"; console.log(" the file path ", fileNameOneChar ); …
elcomputerguy
  • 141
  • 1
  • 9
3
votes
2 answers

Running mocha tests synchronously

I have the following setup for running the 'it' tests: X is environment variable if( X == "all" || X == "some value" ) read directory and run test using it() with callbacks if( X == "all" || X == "some other value") read directory and run…
learn_develop
  • 1,065
  • 3
  • 11
  • 29
3
votes
1 answer

grunt testing api with supertest, express and mocha

I have an https server running by express, which i test using mocha and supertest. My problem is - if i run only the test - its ok. If i try to run gruntfile with test then run express - i see lot of EADDRINUSE errors, even if in test files i do…
Jarema
  • 2,874
  • 2
  • 14
  • 29
3
votes
1 answer

How can i synchronous test with supertest

codes: should = require('should') request = require('supertest') request = request("stackoverflow.com"); describe "temp", -> input_output = [ { input:"[mocha] [supertest]", output: ["asdf", "asdf"] } { input:"아버지가방에들어가신다",…
3
votes
1 answer

Mocha test case for query based functions

I am new to Mocha. Can someone suggest how to write test case for "retrieveEmployee" function. var mysql = require('mysql'); var dbconfig = { host:'localhost', user:'root', password:'root', database:'db', …
Sivakumar
  • 305
  • 1
  • 12
3
votes
1 answer

How do I wrap Mocha/Chai tests within asynchronous functions?

I am working on a framework with modules which are loaded asynchronously using promises. These modules contain methods (which, for this question, can be assumed to be synchronous) for which I would like to create tests for. Currently, my code…
Alvin Teh
  • 615
  • 9
  • 13
3
votes
1 answer

How to test runtime arguments via mocha?

I am using mocha to test some code that I'm writing in node.js. One of my programs is designed to run from the command line with runtime arguments. As several of the options are directories, the code validates the options and determines if the…
Metalskin
  • 3,458
  • 5
  • 35
  • 59
3
votes
0 answers

Grunt - pass cli arguments to another js file

I'm not sure if this is possible or not, but I'm wondering if it's possible to use a grunt task argument to dynamically require another file. Background: I'm using mocha-casperjs to webdrive and test client websites. Each test is defined by json…
AdamPat
  • 101
  • 10
3
votes
2 answers

How to start/stop NodeJS server only once when running test suites

I'm writing selenium test suites for NodeJS. Here's one sample test file: var Sails = require('sails'); // create a variable to hold the instantiated sails server var app; var client; // Global before hook before(function(done) { // Lift Sails…
3
votes
3 answers

Connecting to a PHP website with Node.js and keep session

I'm making a testbench with Test'em and Mocha (that run on node.js) in order to test a PHP website. What I want is to request some URL (e.g http://www.my-website/test.php) and get the http status code as well as the content returned. I'm doing it…
Michaël
  • 970
  • 1
  • 13
  • 29
3
votes
2 answers

How can I run mocha tests remotely on IntelliJ IDEA 13 (or WebStorm)?

IntelliJ IDEA 13 has really excellent support for Mocha tests through the Node.js plugin: https://www.jetbrains.com/idea/webhelp/running-mocha-unit-tests.html The problem is, while I edit code on my local machine, I have a VM (vagrant) in which I…
Tom Frost
  • 1,015
  • 11
  • 20
3
votes
1 answer

Mocking constructor of $resource object in AngularJS

I'm using AngularJS and my tests are in mocha+sinon+chai The code I'm trying to test looks like this: addModal.result.then(function (clientFeature) { if (clientFeature) { //create a new $resource ClientFeature…
shaunlim
  • 4,294
  • 6
  • 29
  • 37
1 2 3
99
100