<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d" -->

---
title: How to Manage Flaky Tests in Jest | daily.dev
description: This post discusses strategies for identifying and managing flaky tests in Jest. It covers common causes of flakiness, such as mocking the wrong selector, hard...
canonical: https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Manage Flaky Tests in Jest | daily.dev
og:description: This post discusses strategies for identifying and managing flaky tests in Jest. It covers common causes of flakiness, such as mocking the wrong selector, hard...
og:url: https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d
og:image: https://api.daily.dev/og/posts/b8R4VvZ4d.png
og:image:alt: How to Manage Flaky Tests in Jest
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Manage Flaky Tests in Jest

**[Semaphore](https://daily.dev/sources/semaphore)** · 9 min read · 0 upvotes · 0 comments

## Summary

This post discusses strategies for identifying and managing flaky tests in Jest. It covers common causes of flakiness, such as mocking the wrong selector, hard coding wait timers, and wrong use of async in Jest tests. The post also provides best practices for writing reliable tests, including using deterministic inputs and outputs, handling asynchronous operations properly, avoiding timing-based logic, and managing external dependencies and state. By following these practices, developers can enhance the stability and reliability of their Jest tests.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://semaphoreci.com/blog/flaky-tests-jest>

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#testing](https://daily.dev/tags/testing), [#jest](https://daily.dev/tags/jest)

[View this post on daily.dev](https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Manage Flaky Tests in Jest","url":"https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d"},"datePublished":"2024-04-02T13:29:31.779Z","dateModified":"2024-05-09T08:43:33.910Z","description":"This post discusses strategies for identifying and managing flaky tests in Jest. It covers common causes of flakiness, such as mocking the wrong selector, hard...","image":"https://media.daily.dev/image/upload/s--0_ODbtD2--/f_auto/v1722860399/public/Placeholder%2008","thumbnailUrl":"https://media.daily.dev/image/upload/s--0_ODbtD2--/f_auto/v1722860399/public/Placeholder%2008","isAccessibleForFree":true,"articleSection":"Semaphore","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Semaphore","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/901ef6f52ded4eb99564604b8bdaee28","url":"https://daily.dev/sources/semaphore"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-manage-flaky-tests-in-jest-b8r4vvz4d","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,testing,jest","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Semaphore","item":"https://daily.dev/sources/semaphore"},{"@type":"ListItem","position":3,"name":"How to Manage Flaky Tests in Jest"}]}
```

