Category : chai

So, I am trying to write some unit tests for my code using MochaJS, SinonJS, rewire, chai and assert. An i got the following error: 1) async function addOneRoom(db, newRoom) should reject error when the maximum room number has been reached: AssertionError [ERR_ASSERTION]: Missing expected rejection (Error). at async Context.<anonymous> (testtest.js:33:9). So the function I ..

Read more

I want to run a couple of tests in NodeJS Code testing the availability of an API endpoint. Not by doing ‘npm run test’ but in regular code. But when using Chai.Expect, it ignores Try/Catch blocks, throws an error and crashes the program. Following code is what I use: run_test2.js const {alive} = require(‘../test/alive’); try ..

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

I am receiving URLs as output and there are certain URLs that I don’t want. How should I remove them by inserting a condition? describe(‘image block’, () => { (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setRequestInterception(true); // page.on(‘console’, msg => console.log(‘PAGE LOG:’, msg.text)); page.on(‘pageerror’, error => ..

Read more