# Avoid Nesting when you're Testing

DevFeed: [Avoid Nesting when you're Testing](<https://devfeed.tech/articles/avoid-nesting-when-you-re-testing-51733.md>)

Original publisher: [Read original article](<https://kentcdodds.com/blog/avoid-nesting-when-youre-testing>)

Author: Kent C Dodds

Published: 2019-07-29T00:00:00Z

Content type: article

Language: en

Sources: [Kent C. Dodds Blog](<https://devfeed.tech/sources/kent-c-dodds-blog.md>)

Topics: [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [React](<https://devfeed.tech/topics/react.md>), [Jest](<https://devfeed.tech/topics/jest.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [hooks](<https://devfeed.tech/topics/hooks.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [hooks](<https://devfeed.tech/tags/hooks.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [jest](<https://devfeed.tech/tags/jest.md>), [nesting](<https://devfeed.tech/tags/nesting.md>), [react](<https://devfeed.tech/tags/react.md>), [react-component](<https://devfeed.tech/tags/react-component.md>), [reuse](<https://devfeed.tech/tags/reuse.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This article explains why nested tests and hooks such as beforeEach can make test suites harder to maintain. Using React component tests as an example, it recommends avoiding unnecessary abstractions and nesting so developers spend less effort tracing setup, variables, and reassignment.

## Source excerpt

Why using hooks like beforeEach as a mechanism for code reuse leads to unmaintainable tests and how to avoid it.