Jasmine is a popular JavaScript testing framework, and it now supports async and await calls in tests. This is a big help in cleaning up tests where you previously had to put asserts in a .then() or .catch() callback.

I've written before about how you can use Jasmine's done keyword to test async specs, but here's a quick recap. You pass in a special Jasmine done parameter, then you invoke the done() function after your async code has completed, usually inside a .then() or a .catch() statement, like this.

describe("Testing async functions", () => {
  
  it("Should work using done", done => {
    // Arrange
    let flag = false;

    // Act
    flag = returnTrueAsync()
      .then(() => {
        // Assert
        expect(flag).toBeTruthy();
        done();
    });
  }); 
  
});

function returnTrueAsync() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(true);
    }, 1000);
  });
}

With version 2.8 and later of Jasmine and your compiler that supports async/await (e.g., Babel, TypeScript), you can change this to be more readable, like this.

describe("Testing async functions", () => {
  
  it("Should work with async/await", async () => {
    // Arrange
    let flag = false;

    // Act
    flag = await returnTrueAsync();

    // Assert
    expect(flag).toBeTruthy();
  }); 
  
});

function returnTrueAsync() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(true);
    }, 1000);
  });
}

Much cleaner!