Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a Promise from "describe" is not supported. Tests must be defined synchronously

Particular test passed but I am getting this.

    console.log node_modules/jest-jasmine2/build/jasmine/Env.js:502           ●   Test suite failed to run              Returning a Promise from "describe" is not supported. Tests must be defined synchronously.             Returning a value from "describe" will fail the test in a future version of Jest.          > 4 | describe('handlers.getSemesters', async () => { 

Here is complete test code

describe('handlers.getSemesters', async () => {       it('should return an array of Semesters', async () => {         academicCalendarRequest.request = jest.fn();         academicCalendarRequest.request.mockReturnValue([           {             description: 'Semester1',           }         ]);         const expected = [                 {             description: 'Semester1',           },         ];          const handlers = new Handlers();         const actual = await handlers.getSemesters();         expect(actual).toEqual(expected);       });     }); 

How can I fix it?

like image 253
Developer Avatar asked Jun 17 '19 23:06

Developer


People also ask

Is Jasmine asynchronous?

Jasmine is a very popular JavaScript behavior-driven development (In BDD, you write tests before writing actual code) framework for unit testing JavaScript applications. It provides utilities that can be used to run automated tests for both synchronous and asynchronous code.

What is done () in Jasmine?

If the function passed to Jasmine takes an argument (traditionally called done ), Jasmine will pass a function to be invoked when asynchronous work has been completed.

How do I stop async calls?

You can cancel an asynchronous operation after a period of time by using the CancellationTokenSource. CancelAfter method if you don't want to wait for the operation to finish.

Does Jasmine support asynchronous operations Mcq?

Q: Does Jasmine support asynchronous operations? Ans: It's possible that the functions you supply to beforeAll, afterAll, beforeEach, and afterEach are asynchronous.


1 Answers

Change

describe('handlers.getSemesters', async () => { 

To

describe('handlers.getSemesters', () => { 

And then put asynchronous code inside of it block

it('should return an array of Semesters', async () => {   // ... }) 
like image 155
Kirk Strobeck Avatar answered Sep 17 '22 12:09

Kirk Strobeck