How to mock middleware in Express to skip authentication for unit test?

You can use sinon to stub isAuthenticated method, but you should do that before a reference to auth.isAuthenticated is set as a middleware, so before you require the index.js and app is created. Most likely you would want this in a beforeEach hook: var app; var auth; beforeEach(function() { auth = require(‘../wherever/auth/auth.service’); sinon.stub(auth, ‘isAuthenticated’) .callsFake(function(req, … Read more

Proxyquire, rewire, SandboxedModule, and Sinon: pros & cons

It totally feels like cheating, but since no one else is answering the question, here goes: Proxyquire takes over require and lets you inject fakes anywhere in the dependency chain. For requires you don’t take over and for methods you don’t define for requires you do take over, it’ll fall back to the original. This … Read more

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