Category : mocha.js

How to stubbing S3 upload in Node.js? I’m using Mocha and Sinon. And I have a file that exports a class instance that including the upload method. It looks like this: // storage.ts export class Storage { private readonly s3: AWS.S3 = new AWS.S3({ endpoint: MINIO_ENDPOINT, accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY, s3ForcePathStyle: true, signatureVersion: ‘v4’, }); ..

Read more

This is my folder structure. /node_modules/ …. …. /src/ …. index.ts export default app.listen(PORT, () => { console.log(‘Server is listening on port 3000’) }); …. tsconfig.json { "compilerOptions": { "target": "esnext", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "typeRoots": [ "@types", "./node_modules/@types" ] }, "include" : [ "src/**/*.ts" ], "exclude" : [ ..

Read more

I have a mocha test that looks like below. describe(‘test suite’, function() { it(‘test case 1’, function(done) { helper.foo(function(result) { done(); }); }); it(‘test case 2’, function(done) { helper.foo(function(result) { done(); }); }); } Both test cases call a method that takes a few minutes to return. If I run this test as is, the ..

Read more

I have the following code. export const someFunction = (body) => { const params = { // }; const sns = new AWS.SNS({ region: process.env.REGION }); return sns.publish(params).promise(); }; I have the following test.js code. const AWS = require(‘aws-sdk’); return someFunction(mockBody).then(response => { expect(AWS.SNS.called).to.be.true; expect(AWS.SNS.getCall(0).args).to.deep.equal([{ region: ‘us-east-1’ }]); // what other test cases }); How ..

Read more