Now, perhaps there is this zany developer on your team who keeps changing API endpoints on you — quite literally breaking things in the process. You decide to write a test that hits those endpoints and makes sure you’re getting back from it what you expect. Straightforward enough. The only slightly tricky part is that API requests are async. To really test it, the test needs to have some way to wait for the results before testing the expectations.
That can be handled in Jasmine through a
beforeEach(), which can wait to complete until you call a
done() function. Here’s the whole thing:
Here’s largely the same thing but with Mocha/Chai:
Source : CSS-Tricks