Implementing the observer pattern using TDD

We will see how we can use TDD to implement the observer pattern. We will use the red, green, and refactor life cycle of TDD to understand it in more detail.

Red step (code with error)

Let's try to add code, which has some dependency. Don't include dependency in the first step and see what error it's giving. Normally in the red step, we have some code with error, and then in next step we add proper code to make it green.

<script type="text/javascript"> Object.defineProperty(employee.status, 'Active', { get: function () { return inactive; }, set: function (status) { Object.getNotifier(this).notify({ type: 'update', name: 'Inactive', oldValue: inactive }); // Let's also print the value in logger anytime it ...

Get Test-Driven JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.