What is TDD?

Whether you’re new to software development or have been around for awhile, you may have heard of TDD, but have never really gotten a full explanation of the process and benefits of adoption. The purpose of this post is to give you a quick introduction to TDD and hopefully pique your interest if you don’t already have TDD in your arsenal of tools.

So what is TDD? To put it simply,

TDD (Test Driven Development) is a methodology of developing software
that relies on very short feedback loops using unit tests.

To practice TDD, start with a failing unit test. Then write only enough code to make that test pass. Finally, refactor the production and unit test code you’ve written. Repeat. This cycle is often called Red Green Refactor cycle. …


In my previous post, Angular Component Class Tests, I shared why I prefer to write my Angular unit tests exclusively as component class tests. In this post, I want to share a simple function I use to create typed stubs.

In my previous post, you’ll notice I had to cast my dependencies to the Typescript any type in order to inject them into the constructor. Here’s that example again:

Now, I could have easily used the real type of my service dependency and simply stubbed all of its methods. That is easy enough if your dependency only has a few properties. However, if you’re injecting something like Angular’s Router which has many methods and properties that need to be defined, that strategy can get cumbersome quickly. Speaking in pure JavaScript terms, what you really want is just an object that has all of the properties of the TypeScript type you’re trying to mock set to undefined. …


Image for post
Image for post
Photo by Daniel von Appen on Unsplash

When testing Angular components, I almost exclusively use component class tests. These are tests that do not use the TestBed and allow you to test a component the same way you would test a service.

The main reason I prefer component class tests is that they are much easier to write than using the TestBed. They don’t require you to setup a test module. Simply call the constructor of the class under test and you’re ready to go! Does your component depend on some services? Simply create stub functions or Jasmine spies and inject them into the constructor in a beforeEach function. …


Image for post
Image for post
Photo by Karen Ciocca on Unsplash

Summary: Any ngModel in child components inside a parent component with a form element will not be added to that form’s controls array. This post shows one solution to this problem.

At work, we recently came up against an interesting problem using child components in parent form components. I imagine many more teams will encounter this issue, so I’m writing this article to share the solution we found.

Background

Our project is a typical business application comprised mostly of forms. Validation is handled primarily by the server and invalid submissions are returned as HTTP Bad Requests with a model state object describing the errors on each form element. …


It’s a wonderful time to be a software developer. The opportunities are abundant and the languages, frameworks, and tooling we use to do our jobs are amazing thanks in large part to our collaborative efforts in the open source world.

One negative aspect I see of this proliferation of excellent libraries and frameworks is the consumer mindset it can bring forth in developers. I think we all struggle with it, and my own struggles in this area are what inspired me to write this post.

The point of this post is not to divide all developers into either “engineer” or “user”. I believe everyone experiences moments on each side. The point is to recognize when we’re acting like users, and to change to the engineer mindset instead. …

About

John Oerter

Software Developer from Omaha, NE.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store