antonosmond / mock-aws

Mock aws-sdk API methods to enable easier testing of apps which use the AWS SDK for JavaScript
ISC License
14 stars 10 forks source link

TypeError: Cannot read property 'clients' of undefined #2

Open ShaneC-C-Y opened 8 years ago

ShaneC-C-Y commented 8 years ago

Hi there, I am new to this module. I have a problem when using mock-awe with dynamodb I found this doesn't support dynamodb DocumentClient.

The test.js

var AWS = require('mock-aws'),
    expect = require('chai').expect,
    get_info = require('../get_info');

const context = require('aws-lambda-mock-context');
const ctx = context();

...
var testData = require('./testData.json')
AWS.mock('DynamoDB.DocumentClient', 'scan', testData);
get_info.handler({}, ctx, function(err, data){
    ...
});
...

The following is get_info.js

var AWS = require("aws-sdk");
AWS.config.update({
  region: "us-west-2",
});

exports.handler = (event, context, callback) => {
    var docClient = new AWS.DynamoDB.DocumentClient();
    var params = {
        TableName:table,
        ProjectionExpression: "deltaEndpoint, tag"
    }
    docClient.scan(params, onScan);
    function onScan(err, data) {
         ....
    }
};

This will return TypeError: Cannot read property 'clients' of undefined

But it can work if I use

var db = new AWS.DynamoDB();
db.scan(params, onScan);

Is there any way to fix this problem?

jestinjht commented 7 years ago

I'm having this problem too. I'm using aws-sdk 2.2.20 and mock-aws 1.2.3

Rukenshia commented 7 years ago

We also have this problem.

andrewhiles commented 6 years ago

I'm encountering the same issue.