0

我正在尝试验证我是否为 SNS 的服务 ctor 提供了正确的参数,但我不知道该怎么做。

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

这是一些伪代码:

//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
    });
});
4

1 回答 1

0

从以下文档aws-sdk-mock

在顶级 node_modules 项目文件夹中不包含 `aws-sdk` 的项目结构将不会被正确模拟。这方面的一个示例是在嵌套项目目录中安装“aws-sdk”。您可以通过使用 `setSDK()` 显式设置嵌套 `aws-sdk` 模块的路径来解决此问题。
//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
    });
});
于 2019-04-11T04:48:08.660 回答