Refactoring our code

At this point, everything is okay; we have our test and implementation written, the code is doing what we expect, and it seems that there's nothing left to do. But, as a good developer, we should look for ways to make our code more readable and reduce the lines of code. Also, the refactoring phase is used to change some weird variable names and, if possible, add comments to our code if needed.

Open your testing.js file and apply the following changes to make it more readable:

var assert = require('assert');

function add(n1, n2) {
return n1 + n2;
}

assert.equal(add(5, 5), 10, "Should be 10");

console.log("Test passed!!");

The first change is in the add function. As this is a simple addition operation, declaring a result variable is not necessary, so we return the addition result in the return function to make it more readable.

Finally, we are passing the results of the call to add(5, 5) into the assert.equal function, so it is easier to know what you are trying to test.

As you might see, TDD is easy to implement but a little bit hard to adopt; we (the authors :D) encourage you to adopt and use it at work. This will make your life easier and will help you become a better programmer who knows how to deliver quality software.

Now it's time to see what Aurelia has to offer. Keep reading!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset