How to test the type of a thrown exception in Jest

I’m working with some code where I need to test the type of an exception thrown by a function (is it TypeError, ReferenceError, etc.?). My current testing framework is AVA and I can test it as a second argument t.throws method, like here: it(‘should throw Error with message \’UNKNOWN ERROR\’ when no params were passed’, … Read more

How can I mock an ES6 module import using Jest?

I want to test that one of my ES6 modules calls another ES6 module in a particular way. With Jasmine this is super easy — The application code: // myModule.js import dependency from ‘./dependency’; export default (x) => { dependency.doSomething(x * 2); } And the test code: //myModule-test.js import myModule from ‘../myModule’; import dependency from … Read more

Message “Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout”

I’m using Puppeteer and Jest to run some front end tests. My tests look as follows: describe(“Profile Tab Exists and Clickable: /settings/user”, () => { test(`Assert that you can click the profile tab`, async () => { await page.waitForSelector(PROFILE.TAB); await page.click(PROFILE.TAB); }, 30000); }); Sometimes, when I run the tests, everything works as expectedly. Other … Read more

What is the difference between ‘it’ and ‘test’ in Jest?

I have two tests in my test group. One of the tests use it and the other one uses test. Both of them seem to be working very similarly. What is the difference between them? describe(‘updateAll’, () => { it(‘no force’, () => { return updateAll(TableName, [“fileName”], {compandId: “test”}) .then(updatedItems => { let undefinedCount = … Read more