I'm currently attempting to test one my middleware which uses AWS, is there a way to do this by stubbing the AWS module in the middleware file with the mock-aws version?
const mockHttp = require('node-mocks-http');
const proxyquire = require('proxyquire');
const AWS = require('aws-sdk-mock');
AWS.mock('SNS', 'listTopics', () => [{ TopicArn: 'foobar' }]);
const snsTopics = proxyquire('../../src/middleware/sns_topics', {
'aws-sdk': AWS,
});
describe.only('middleware > snsTopics', () => {
it('should create an topic in the DB if it doesnt exist and return a topicArn', async () => {
const req = mockHttp.createRequest({ registration: '' });
await snsTopics(req, {}, () => {});
expect(req.topicArn).to.equal('foobar');
AWS.restore('SNS', 'listTopics');
});
});
I think I'm having the same issue. I suspect node-mocks-http is the problem. Some interaction between AWS requests and node-mocks-http is breaking things.
Hey everyone,
I'm currently attempting to test one my middleware which uses AWS, is there a way to do this by stubbing the AWS module in the middleware file with the mock-aws version?
middleware is using
promise()
:the error I'm receiving is
TypeError: sns.listTopics(...).promise is not a function
sns.listTopics()
returns:It seems the function is not being mocked? I've tried to change the mock to be just a string but receive the same output.