James Hickey's Blog

Looking At Software Related Ideas Using Short And To The Point Code Samples :)

Menu Close

Tag: javascript

Tips For Readable And Maintainable Unit Tests In JavaScript / TypeScript

I’ve started using ts-jest for a project at work and have really enjoyed it. It works great because you can write your tests in TypeScript and ts-jest will just compile on-the-fly then run your tests like you would expect. However, tests can easily become unreadable or harder-to-read (which isn’t limited to ts-jest, of course).

Improving Readability

In order to make the tests more readable, I am creating generic functions that I can re-use in my test cases. Read more

Using TypeScript Decorators To Clean-Up Mixins

Lately I’ve been migrating a JavaScript framework I built (for a work client) over to TypeScript. The core UI components are built using mixins. Using jQuery extend(), the JavaScript code would have done something like:

var TextBox.prototype = $.extend({ ...some object with functions and state....}, CanDoExtraStuff, CanDoOtherCoolStuff);

One of the first things I was hoping TypeScript would allow was to clean this up and make it clearer what was going on.

Read more

© 2017 James Hickey's Blog. All rights reserved.

Theme by Anders Norén.