today is tomorrow's past

today is tomorrow's past

I help people create remarkable things. Focus on the customer and quality. Opinions are my own. Photography is my other passion.

Efficient JavaScript Unit Testing with Jest and Snapshots

Make your software testing life easier with Jest and Snapshots to test your javascript code

Ingo Richter

7-Minute Read

Let’s start with a bold statement: We all love to write unit great tests for our code. More or less. — Unknown Programmer Writing unit tests for my code mostly follows this pattern Write a test and make it fail (red) Write the function to fix the test (implement function) Start over with step 1 For one of my projects, I was using jest. It’s fast now, and it has several features that I highly value.

1-Minute Read

I was building a Reactjs component, that should toggle between two child components. <Toggle> <Comp1> <Comp2> </Toggle> The render method of Toggle looked like this render() { const content = React.Children.count(this.props.children) > 0 ? this.props.children[0] : this.props.children[1]; return ( ${content} ); } Unfortunately, this didn’t work (index out of bounds), when I passed only one component instead of two. This doesn’t make sense since the Toggle is supposed to toggle between two components.

1-Minute Read

I was testing an ant based build script change today. And I thought ant was already retired. Running the script led to a lot of warnings about a missing library. I asked the person, if there are any dependencies for ant-contrib. His response was “yes, you need to install ant-contrib”. First of all, I didn’t have ant installed. But that was easy with irichter@irichter-MacBookPro:~ brew2 install ant Unfortunately, ant-contrib wasn’t available via homebrew, so I had to download it and place it… where?

Recent Posts

Categories

About

Always something to think about