How do i test my express app with mocha?

found an alternative in connect.js tests suites They are using supertest to test a connect app without binding the server to any port and without using mock-ups. Here is an excerpt from connect’s static middleware test suite (using mocha as the test runner and supertest for assertions) var connect = require(‘connect’); var app = connect(); … Read more

How to assert not null?

Mocha supports any assertion library you want. You can take a look at how it deals with assertions here: http://mochajs.org/#assertions. I don’t know which one you want to use. Considering you are using Chai, which is pretty popular, here are some options: Consider “foo” to be the target variable you want to test Assert var … Read more

Running the same mocha test multiple times with different data

A basic approach to run the same test with different data is to repeat the test in a loop providing the data: describe(‘my tests’, function () { var runs = [ {it: ‘options1’, options: {…}}, {it: ‘options2’, options: {…}}, ]; before(function () { … }); runs.forEach(function (run) { it(‘does sth with ‘ + run.it, function … Read more

Jasmine vs. Mocha JavaScript testing for Rails 3.1+ [closed]

I have done testing in both Jasmine and Mocha. First, switching is relatively easy. The basic describe and it BDD pattern is identical. You will need to change how you do your assertions and switch to a different interface for asynchronous tests. Overall they are comparable. Mocha’s asynchronous interface is much simpler and more consistent. … Read more

How to authenticate Supertest requests with Passport?

As zeMirco points out, the underlying superagent module supports sessions, automatically maintaining cookies for you. However, it is possible to use the superagent.agent() functionality from supertest, through an undocumented feature. Simply use require(‘supertest’).agent(‘url’) instead of require(‘supertest’)(‘url’): var request = require(‘supertest’); var server = request.agent(‘http://localhost:3000’); describe(‘GET /api/getDir’, function(){ it(‘login’, loginUser()); it(‘uri that requires user to be … Read more

Verify that an exception is thrown using Mocha / Chai and async/await

The problem with this approach is that (await fails()).should.throw(Error) doesn’t make sense. await resolves a Promise. If the Promise rejects, it throws the rejected value. So (await fails()).should.throw(Error) can never work: if fails() rejects, an error is thrown, and .should.throw(Error) is never executed. The most idiomatic option you have is to use Chai’s rejectedWith property, … Read more

How can I check that two objects have the same set of property names?

You can serialize simple data to check for equality: data1 = {firstName: ‘John’, lastName: ‘Smith’}; data2 = {firstName: ‘Jane’, lastName: ‘Smith’}; JSON.stringify(data1) === JSON.stringify(data2) This will give you something like ‘{firstName:”John”,lastName:”Smith”}’ === ‘{firstName:”Jane”,lastName:”Smith”}’ As a function… function compare(a, b) { return JSON.stringify(a) === JSON.stringify(b); } compare(data1, data2); EDIT If you’re using chai like you say, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)