I have the following test:
const AWSMock = require('aws-sdk-mock');
const AWS = require('aws-sdk');
const sinon = require('sinon');
function sendMetric() {
const cloudwatch = AWS.CloudWatch();
cloudwatch.putMetricData();
}
describe('Meh', () => {
it('meh', () => {
let sendMetricSpy = sinon.spy();
AWSMock.mock('CloudWatch', 'putMetricData', sendMetricSpy);
sendMetric();
expect(sendMetricSpy.calledOnce).toEqual(true);
});
});
I expect the test to pass, because I have done what the documentation says. This is a distilled example of what I am trying to achieve in my actual code.
The actual output from running the test is:
FAIL functions/monitor/__test__/j.test.js
Meh
✕ meh (10ms)
● Meh › meh
expect(received).toEqual(expected) // deep equality
Expected: true
Received: false
14 | AWSMock.mock('CloudWatch', 'putMetricData', sendMetricSpy);
15 | sendMetric();
> 16 | expect(sendMetricSpy.calledOnce).toEqual(true);
| ^
17 | });
18 | });
19 |
I don't know how troubleshoot this further.
I have also tried setting the aws-sdk
object explicity, which had the same result.
What am I doing wrong?