# prefer-assert-throws πŸ“ Prefer `assert.throws()`/`assert.rejects()` over try/catch with an assertion. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-node-test#preset-configs). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-node-test#preset-configs). Using `assert.throws()` or `assert.rejects()` is cleaner and more expressive than wrapping throwing code in a try/catch with assertions in the catch block. ## Examples ```js import assert from 'node:assert'; // ❌ try { throwingFn(); } catch (error) { assert.ok(error instanceof TypeError); } // ❌ try { await asyncFn(); } catch (error) { assert.ok(error instanceof TypeError); } // βœ… assert.throws(() => throwingFn(), TypeError); // βœ… await assert.rejects(() => asyncFn(), TypeError); ```