Post request via Chai

The way you have written, I assume that you used chai-http package. The .field() function does not work in chai-http. Another user pointed it out here and opened an issue on github. Here is how you could have written: .set(‘content-type’, ‘application/x-www-form-urlencoded’) .send({myparam: ‘test’}) Here is the full code that successfully passes parameters to the server: … Read more

Match partial objects in Chai assertions?

chai-subset or chai-fuzzy might also perform what you’re looking for. Chai-subset should work like this: expect([ { C1: ‘xxx’, C0: ‘this causes it not to match.’ } ]).to.containSubset([{C1: ‘xxx’}]); Personally if I don’t want to include another plugin I will use the property or keys matchers that chai includes: ([ { C1: ‘xxx’, C0: ‘this … Read more

Mocha, Chai: Assert that Object is included in an Array of Objects

Here is an alternative and non order dependent approach for collections: array expect([1, 2, 3]).to.include.members([3, 2, 1]) You can also use this with a deep flag for comparison of objects: array of objects expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]); object expect({foo: ‘bar’, width: 190, height: 90}).to.include({ height: 90, width: 190 })

How to unit test express Router routes

If you just want to unit test the route’s presence and its method, you can do something like this: auth.router.js import { Router } from ‘express’; const router = Router(); router.post(‘/signup’, signupValidation, signupUser); router.post(‘/login’, loginValidation, loginUser); router.post(‘/reset’, resetValidation, setPasswordReset); export default router; auth.router.spec.js test(‘has routes’, () => { const routes = [ { path: ‘/signup’, … Read more

Chai – Testing for values in array of objects

This is what I usually do within the test: var result = query_result; var members = []; result.forEach(function(e){ members.push(e.title); }); expect(members).to.have.members([‘expected_title_1′,’expected_title_2’]); If you know the order of the return array you could also do this: expect(result).to.have.deep.property(‘[0].title’, ‘expected_title_1’); expect(result).to.have.deep.property(‘[1].title’, ‘expected_title_2’);

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