首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >aws-sdk-mock验证服务ctor调用SNS

aws-sdk-mock验证服务ctor调用SNS
EN

Stack Overflow用户
提问于 2019-02-27 04:31:31
回答 1查看 567关注 0票数 0

现在,我确实知道如何验证发布,但我再次尝试验证对SNS函数/ctor的期望。

下面是一些伪代码:

代码语言:javascript
复制
//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
    });
});
EN

回答 1

Stack Overflow用户

发布于 2019-04-11 12:48:09

aws-sdk-mock 文档中的

在顶层

项目文件夹中不包含aws-sdk的node_modules项目结构将不会被正确模拟。例如,将aws-sdk安装在嵌套的项目目录中。您可以通过使用setSDK().

显式设置嵌套aws-sdk模块的路径来解决此问题

代码语言:javascript
复制
//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
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54893610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档