Simple aws-sdk-mock timeout without calling callback

I am currently writing some unit tests in nodejs using mocha . I recently tried to learn how to mock the Amazon Web Services SDK using the aws-sdk-mock module and the explanations on the same page.
I came up with a short test that supposedly mocks the "Get" operation of the DynamoDB DocumentClient, gets called once and writes the return value ... Here is the code:

var AWS = require('aws-sdk');
var AwsMock = require('aws-sdk-mock');
describe("xyz", function() {
    it('should call "get" on mock database', function(done) {
        AwsMock.mock('DynamoDB.DocumentClient', 'get', function(params, callback) {
            callback(null, {
                Item: {
                    Key: 'Value'
                }
            });
        });
        var dynamoDb = new AWS.DynamoDB.DocumentClient();
        dynamoDb.get({}, function(err, data) {
            console.log('data: ' + JSON.stringify(data));
            done();
        });
    });
});

      

However, for some reason this eludes me, this test keeps failing with a timeout error as the callback error was apparently never called. This is the complete test result:

xyz
    1) should call "get" on mock database

  0 passing (2s)
  1 failing

  1) xyz should call "get" on mock database:
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

npm ERR! Test failed.  See above for more details.

      

I suppose I followed the explanations on the aws-sdk-mock page very closely (I copied the mock unchanged) and I cannot find an error in this code. I've searched google and Stackoverflow but couldn't find a similar question, so can someone tell me where is the problem?

Thanks in advance.

+3


source to share





All Articles