I'm beginner with mocking in Typescript. I want to mock AWS.Comprehend
in my unit test. I have this code with AWS Service Comprehend.
const comprehend = new AWS.Comprehend();
export const handler = async (): Promise<any> => {
const params = {
JobName: "first-job",
InputDataConfig: {
S3Uri: "input_bucket_name",
InputFormat: "ONE_DOC_PER_FILE"
},
OutputDataConfig: {
S3Uri: "output_bucket_name"
},
DataAccessRoleArn: "role_arn"
};
const result = await comprehend.startDominantLanguageDetectionJob(params)
.promise()
.catch(error => {
throw error;
}
);
return result.JobId;
};
I try to write an unit test for my code.
import { expect } from 'chai';
import * as AWSMock from 'aws-sdk-mock';
import * as AWS from 'aws-sdk';
describe('unitTest', () => {
before(() => {
AWSMock.setSDKInstance(AWS);
AWSMock.mock('Comprehend', 'startDominantLanguageDetectionJob', (params, cb) => {
cb(null, { jobId: 'test_job_id', JobStatus: 'SUBMITTED' });
});
});
it('should pass', async () => {
const result = await handler();
expect(result).to.be.eql('test_job_id');
});
});
But my code doesn't work. It seems to me that Comprehend
is not a mock. And running normal startDominantLanguageDetectionJob not mock.
What is my error with using aws-sdk-mock
?