惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
T
Tenable Blog
博客园_首页
P
Privacy International News Feed
博客园 - 聂微东
S
Schneier on Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
T
Tor Project blog
The Hacker News
The Hacker News
P
Proofpoint News Feed
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 司徒正美
C
Check Point Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
T
Troy Hunt's Blog
L
LangChain Blog
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
Latest news
Latest news
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
D
Docker
I
Intezer
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The GitHub Blog
The GitHub Blog
博客园 - 叶小钗
L
LINUX DO - 热门话题
The Last Watchdog
The Last Watchdog
NISL@THU
NISL@THU
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件

Kent C. Dodds Blog

Implementing Hybrid Semantic + Lexical Search Simplifying Containers with Cloudflare Sandboxes Migrating to Workspaces and Nx Offloading FFmpeg with Cloudflare Building Semantic Search on my Content Helping YOU ask ME questions with AI How I used Cursor to Migrate Frameworks The Dow's Start on the Covenant Path 2025 in Review The next chapter: EpicAI.pro AI is taking your job How I increased my visibility Launching Epic Web 2023 in Review Stop Being a Junior RSC with Dan Abramov and Joe Savona Live Stream Fixing a Memory Leak in a Production Node.js App 2022 in Review My Car Accident I Migrated from a Postgres Cluster to Distributed SQLite with LiteFS I'm building EpicWeb.dev A review of my time at Remix Remix: The Yang to React's Yin How I help you build better websites Why I Love Remix The State Initializer Pattern How to React ⚛️ Get a catch block error message with TypeScript Building an awesome image loading experience How Remix makes CSS clashes predictable Introducing the new kentcdodds.com How I built a modern website in 2021 How to use React Context effectively Static vs Unit vs Integration vs E2E Testing for Frontend Apps The Testing Trophy and Testing Classifications Array reduce vs chaining vs for loop Don't Solve Problems, Eliminate Them Super Simple Start to Remix Super Simple Start to ESModules in Node.js JavaScript Pass By Value Function Parameters How to write a Constrained Identity Function (CIF) in TypeScript How to optimize your context value How to write a React Component in TypeScript TypeScript Function Syntaxes Listify a JavaScript Array Build vs Buy: Component Libraries edition Using fetch with TypeScript Wrapping React.useState with TypeScript Define function overload types with TypeScript 2020 in Review Business and Engineering alignment Hi, thanks for reaching out to me 👋 useEffect vs useLayoutEffect Super simple start to Firebase functions Super simple start to Netlify functions Super Simple Start to css variables Favor Progress Over Pride in Open Source Testing Implementation Details How getting into Open Source has been awesome for me useState lazy initialization and function updates Use ternaries rather than && in JSX Application State Management with React Use react-error-boundary to handle errors in React JavaScript to Know for React How I structure Express apps What open source project should I contribute to? When I follow TDD AHA Programming 💡 How I Record Educational Videos Should I write a test or fix a bug? Stop mocking fetch Intentional Career Building Improve test error messages of your abstractions Tracing user interactions with React Eliminate an entire category of bugs with a few simple tools Common mistakes with React Testing Library Super Simple Start to React Stop using client-side route redirects The State Reducer Pattern with React Hooks Function forms Replace axios with a simple custom fetch wrapper How to test custom React hooks React Production Performance Monitoring Should I useState or useReducer? Stop using isLoading booleans Make Your Test Fail Make your own DevTools An Argument for Automation Fix the "not wrapped in act(...)" warning Super Simple Start to ESModules in the Browser Implementing a simple state machine library in JavaScript 2010s Decade in Review Why users care about how you write code Why I avoid nesting closures Don't call a React function component Why your team needs TestingJavaScript.com Inversion of Control Understanding React's key prop How to Enable React Concurrent Mode Profile a React App for Performance
The time I messed up
2018-10-22 · via Kent C. Dodds Blog

We all have stories where automated tests could've saved us from disaster, but I want to tell you a story of a time when I went overboard with a certain testing practice and it went really badly for me...

This was a few years ago. I was working on angular-formly and I had just discovered React's PropTypes feature. I thought it was the coolest thing since sliced bread. lol, I just looked it up and my first issue on the React repo was asking if we could add an objectWith PropType validator. I wrote the whole thing including tests and put that in the issue. Sophie Alpert responded with:

Isn't this what React.PropTypes.shape is for?

Ha! Whoops! Anyway, I decided it'd be really cool to have development-only runtime validation on the configuration object that people pass to angular-formly when configuring their forms.

My second issue on the React repo was asking if the React team would be willing to extract prop types into its own package (this has actually now taken place! Checkout prop-types). That didn't work out, so I decided to write my own package and thus api-check was born!

One of the cool things about a library like this is that the whole thing is a bunch of pure functions! And we all know that pure functions are super easy to test, right?! Also, because I had a very clear picture of what I wanted to implement (with prop-types as my inspiration) I thought test-driven development would be a synch.

So I set to work. I started writing a bunch of tests and implemented api-check as I went. Honestly, it was exhilarating. (I'd say intoxicating, but I've never actually had a drop of alcohol in my life, so I wouldn't know 😅). I was having a blast writing this out.

But as time went on, I started noticing something... It was becoming progressively less fun and more difficult to implement the behaviors as I added them. The library code started getting really complicated. Now I shudder even thinking about it. There's no way you could convince me to work on that code anymore.

So what went wrong? I thought TDD was the process by which you create beautifully and intentionally designed software. But what I was left with is a mess that I don't want to touch. I must have done something wrong...

I did. TDD is a three-step process. It's often referred to as the "red, green, refactor cycle"

TDD Cycle

Here's the way it works:

  • 🚨 Red: Write a test for the function/module you're going to create before it exists/supports the feature you're adding. This gives you a test that fails (you get a "red" error message).
  • Green: Implement just enough code to get that test passing (you get a "green" success message).
  • 🌀 Refactor: Look over the code you have written and refactor it to ensure it's well-written, as easy as possible to read/understand, and well-designed. (The cool thing with this step is that you now have a test in place that will tell you if you break something as you refactor).
  • 🔁 Repeat: It's a cycle, after all 😉 Keep going until you've finished implementing everything you need to.

So where did I go wrong with api-check? Well, I kinda skipped the refactor step. I got so excited from the "high" (another thing of which I'm ignorant) that I felt from turning that red test to a green test that I just continued on with the next feature without stopping to consider if what I was building was at all maintainable. Turns out it wasn't. I was building a monstrosity of difficult-to-understand code. The code was legacy the second it left my fingers.

Conclusion

So, what do we learn from this? Test-driven development is awesome, and it can really help you develop great code in certain situations. But if you skip the refactor step and aren't intentional about what you're building, it can lead to disaster.

Be careful out there, friends. And learn to use TDD the right way with me at TestingJavaScript.com 🏆