0

I'm trying to validate that I supplied the correct arguments into the service ctor for SNS, but I don't know how to do it.

Now, I do know how to validate publish, but again, I'm trying to verify expectations for the SNS function/ctor.

Here's some pseudo code:

//code
const AWS = require('aws-sdk');
const SNS = new AWS.SNS({bobby:'no'});

//test
const AWSmock = require('aws-sdk-mock');

describe('something', () => {
    beforeAll(()=>{
        AWSmock.mock('SNS','publish', Promise.resolve());
    });
    test('doing it', () => {
        const f = require('file');

        expect(AWSmock.SNS.calledWith({})).toEqual(true); //this example would be false, but I can't figure out how to reference the SNS method here
    });
});
KellyTheDev
  • 891
  • 2
  • 12
  • 31

1 Answers1

0

From the documentation of aws-sdk-mock :

Project structures that don't include the `aws-sdk` at the top level node_modules project folder will not be properly mocked. An example of this would be installing the `aws-sdk` in a nested project directory. You can get around this by explicitly setting the path to a nested `aws-sdk` module using `setSDK()`.
//code
const AWS = require('aws-sdk');
const SNS = new AWS.SNS({bobby:'no'});

//test
const AWSmock = require('aws-sdk-mock');
// setting the AWS explicitly might help
AWSMock.setSDKInstance(AWS);

describe('something', () => {
    beforeAll(()=>{
        AWSmock.mock('SNS','publish', Promise.resolve());
    });
    test('doing it', () => {
        const f = require('file');

        expect(AWSmock.SNS.calledWith({})).toEqual(true); //this example would be false, but I can't figure out how to reference the SNS method here
    });
});
Atul Kumar
  • 690
  • 1
  • 9
  • 20