title: Unit testing mocha chai with arguments
body: <p>I m building a little library using Nodejs and I m having some troubles unit testing with mocha and chai.</p>
  
  <p>My problem happens when I try to spy on a function, and expect it to have been called with some parametes.</p>
  
  <p>Actually, when I log, the parameters passed to the function are good. But the test is failing again and again.</p>
  
  <p>Here's what I m testing :</p>
  
  <pre><code>import callback from './callback'
  /**
   * Connect the express routes with the injector directly inside of the app
   * @param  {Object} app      An express application, or an application that has the same api
   * @param  {Object} injector An injector with the interface of deepin module
   * @param  {Object} parser   An object with the interface of route-parser module
   */
  const expressKonnector = (app, injector, parser) =&gt; {
    const routes = parser.parseRoutes()
    for (const route of routes) {
      app[route.method](route.pattern, callback(injector, route))
    }
  }
  
  export default expressKonnector
  </code></pre>
  
  <p>Here's the callback dependent module :</p>
  
  <pre><code>import callbackRender from './callbackRender'
  import { HttpRequest } from 'default-http'
  
  export default (injector, route) =&gt; {
    const ctrl = injector.get(route.controller)
    return (request, response) =&gt; {
      const result = ctrl[route.controllerMethod](new HttpRequest())
      if (result.then) {
        return result.then(res =&gt; callbackRender(res, response))
      } else {
        callbackRender(result, response)
      }
    }
  }
  </code></pre>
  
  <p>And here's the failing test :</p>
  
  <pre><code>  it('should call the app.get method with pattern /users/:idUser and a callback', () =&gt; {
        const spy = chai.spy.on(app, 'get')
        const routes = routeParser.parseRoutes()
        expressKonnector(app, injector, routeParser)
        expect(spy).to.have.been.called.with('/users/:idUser', callback(injector, routes[1]))
      })
  </code></pre>
  
  <p>I have the following stack when the test fails :</p>
  
  <pre><code>ExpressKonnector  ExpressKonnector should call the app.get method with pattern /users/:idUser and a callback:
  AssertionError: expected { Spy, 3 calls } to have been called with [ '/users/:idUser', [Function] ]
  at Context.&lt;anonymous&gt; (C:/Project/javascript/express-konnector/src/test/expressKonnector.spec.js:176:43)
  </code></pre>
  
  <p>If you want to have more detail, or simply run the "npm install &amp;&amp; npm test command", you can have the module on this github (dev branch) :</p>
  
  <p><a href="https://github.com/Skahrz/express-konnector" rel="nofollow">https://github.com/Skahrz/express-konnector</a></p>