现在,我确实知道如何验证发布,但我再次尝试验证对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
});
});发布于 2019-04-11 12:48:09
aws-sdk-mock 文档中的
在顶层
项目文件夹中不包含
aws-sdk的node_modules项目结构将不会被正确模拟。例如,将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
});
});https://stackoverflow.com/questions/54893610
复制相似问题