How to use job-dependencies in tests

Issue #101 resolved
FrankJ created an issue

I'm using the "experimentalConfluence"-API located in atlasboard/lib/job-dependencies and it works fine. I wonder if it is possible to use this dependency in an integration test, since dependencies are not injected automatically in tests and I can not simply require it.

Is there a chance to di this?

Comments (5)

  1. Iván Loire

    You can just mock the dependencies:

        mockedDependencies = {
          logger: console,
          easyRequest : {
            JSON : function (options, cb) {
              cb(null, {});
            }
          }
        };
    

    and they write the job test:

      describe ('http request example tests', function(){
        it('should handle server errors', function (done){
    
          mockedDependencies.easyRequest.HTML = function (options, cb){
            cb(null, 'hello from google');
          };
    
          var config = {};
          job(config, mockedDependencies, function(err, data){
            assert.equal('hello from google', data.html, 'expected reply from goodle but got ' + data.html);
            done();
          });
        });
      });
    
  2. FrankJ reporter

    Thanks, but the point ist that I'd like to use this dependency as it is in job-dependencies, not to mock anything. We do some real-system-integration-testing when we update the Confluence version to check if API calls are still valid, so mocking is not an option here.

  3. Iván Loire

    Not sure how are you running your integration tests. Maybe if you post some code I can give you some directions.

  4. FrankJ reporter

    ok, I ended up using

     var ical = dependencies.ical || require('ical');
    

    So I consider this done.

  5. Log in to comment