Mocha afterEach

Mocha is a JavaScript test framework for Node.js with features like browser support, asynchronous testing, test coverage report, and use of any assertion library.

afterEach() is a hook or global method provided by Mocha that will execute after each test case in a block. It is usually used to clean-up ​after your test cases.

svg viewer

Syntax

afterEach(name, fn)

  • name: Optional string
  • fn: Function to run after each test case
Error: Code Widget Crashed, Please Contact Support

In addition to afterEach(), there is also beforeEach(), which runs before every test case. Read more in the official docs.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved