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?
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.
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.
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.
Q: Does Jasmine support asynchronous operations? Ans: It's possible that the functions you supply to beforeAll, afterAll, beforeEach, and afterEach are asynchronous.
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 () => { // ... })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With