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 gets // set for status console.log('set', status); inactive = b; } }); </script>
When we run the preceding code, we...