Skip to content

Tag: jestjs

Mock AWS SES using jest in typeorm

Need to test AWS SES using jest unit testing But showing different errors, also tried solutions in another stackoverflow question The actual code to be tested is : the test file is : Its giving error message as: Answer Actually this mock works, the reason behind the error is that , i didn’t mocked the AWS.Credentials.

In Jest, how do I cause a function called within the function to return a specific value

This is the function I am testing (stripped down for simplicity’s sake): populate.js-> The function this function calls: populate-template-utilities -> And my unit test (again stripped down): I want createSessionID to return ‘PAX123456’ and think mockID should do it, but it’s erroring with: Answer The spyOn method needs at least two parameters: object and methodName. Try sth like this: It

How to store response body in supertest?

I am testing very basic REST api with supertest. I want to save the item id received in response body and assign it to a variable. Using this id i want to make further tests like get-item-by-id or update-item-by-id. No official documentation has covered this so a beginner friendly answer would be very helpful. test i have written Answer Use

Mock an axios 404 with Jest?

When mocking a 404 error the result is Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason “Error: error”. Setup a basic Mock Create a test case How to mock the 404 request? Answer Using

Can’t mock the navigator.language

I’m currently adding unit test for some of shard utils functions. I’m kinda new to unit testing. Currently having hard time to mock some global object. Is there any way to mock/update value of navigator.language? It is always returning en-US. I tried the Object.defineProperty and different jest mock objects. Didn’t work. The thing is, if I console.log(navigator.language) in the test,