title: NodeJS- ReferenceError: wagner is not defined
body: <p>I don't have experience at all with nodejs and I am learning. I have a code, which I am testing and giving me the following errors, and I don't understand why:</p>
  
  <p>1) Part 3 Assessment Tests "before all" hook:
       ReferenceError: wagner is not defined
        at Object. (fx.js:2:31)
        at Object. (dependencies.js:3:10)
        at Context. (test.js:29:20)</p>
  
  <p>2) Part 3 Assessment Tests "after all" hook:
       TypeError: Cannot read property 'close' of undefined
        at Context. (test.js:65:11)</p>
  
  <p>These are the programs involved in the issue:</p>
  
  <p>test.js --------------</p>
  
  <pre><code>var assert = require('assert');
  var express = require('express');
  var fs = require('fs');
  var status = require('http-status');
  var superagent = require('superagent');
  var wagner = require('wagner-core');
  
  var URL_ROOT = 'http://localhost:3000';
  var PRODUCT_ID = '000000000000000000000001';
  
  describe('Part 3 Assessment Tests', function() {
    var server;
    var app;
    var succeeded = 0;
    var finalCharge;
  
    var Category;
    var Config;
    var fx;
    var Product;
    var Stripe;
    var User;
  
    before(function() {
      app = express();
  
      // Bootstrap server
      models = require('./models')(wagner);
      dependencies = require('./dependencies')(wagner);
  
      // Make models available in tests
      var deps = wagner.invoke(function(Category, fx, Product, Stripe, User, Config) {
        return {
          Category: Category,
          fx: fx,
          Product: Product,
          Stripe: Stripe,
          User: User,
          Config: Config
        };
      });
  ...
  </code></pre>
  
  <p>dependencies.js -------------</p>
  
  <pre><code>var wagner = require('wagner-core');
  var fs = require('fs');
  var fx = require('./fx')(wagner);
  var Stripe = require('stripe');
  
  module.exports = function(wagner) {
    var stripe = 
  
    // TODO: Make Stripe depend on the Config service and use its `stripeKey`
    // property to get the Stripe API key.
    wagner.factory('Stripe', function() {
      return Stripe(Config.stripeKey);
    });
  
    wagner.factory('fx', fx);
  
    wagner.factory('Config', function() {
      return JSON.parse(fs.readFileSync('./config.json').toString());
    });
  
    var Config = wagner.invoke(function(Config) {
        return Config;
     });
  }; 
  </code></pre>
  
  <p>fx.js --------------------------</p>
  
  <pre><code>var superagent = require('superagent');
  var _ = require('underscore')(wagner);
  
  module.exports = function(Config) {
  ...
  };
  </code></pre>
  
  <p>I think I shouldn't have any problem because wagner is defined on test.js and passed as parameter to dependencies.js, and it is passing it on to fx.js. </p>
  
  <p>1- Could you tell me what is wrong in the code ?
  2- The second error, I have not cue why is it happening.</p>
  
  <p>Please, help</p>