Bram's Dev Blog

home

100 Days of Code Day 80 - Analyzer Testing

13 Nov 2018

Break points - identify where it’s going wrong

One of my challenges right now, is that I don’t understand the flow of control during execution of the Karma test runs. As a consequence, I don’t see where the current error is exactly thrown. Already a while ago, I installed the Karma plugin for Intellij IDEA. It seems to have breakpoint support but I don’t know how they work yet.

Learned that these break points and the process of stepping in, stepping over etc, should basically be similar to the java debugger. However, even when put very early in the execution of the test, the test already fails before we get there, with the constructor of my LangSwitchComponent.

TypeError: Cannot read property 'lang' of undefined
    at new LangSwitchComponent (spec-bundle.js:176278:6483)

OnInit ?

My LangSwitchComponent currently implements the OnInit interface and I can’t recall whether this was a conscious need/decision or just a result from copying template code from somewhere.

From this answer: Mostly we use ngOnInit for all the initialization/declaration and avoid stuff to work in the constructor. The constructor should only be used to initialize class members but shouldn’t do actual “work”.

So you should use constructor() to setup Dependency Injection and not much else. ngOnInit() is better place to “start” - it’s where/when components’ bindings are resolved.

When reading this, I noticed and realised that I’m initialising two class members, activeLangs and moreThanOneLanguage, not in the constructor, not in ngOnInit, but just at their declarations. Even thought the code actually worked, I wonder if I should be moving this to the constructor or the ngOnInit method.

Since the initialization of those members depends on the config being present and dependency injection done, it likely makes sense to move them to ngOnInit. Because it’s exactly the lang property that is relied upon, which is what the test run is complaining about.

This definitely made a difference, because some of my tests are now passing!

When to use async for tests?

Noticed that had two of my tests set to async but don’t recally exactly why that’s necessary or preferable.

Day 81 Plan

Continue trying to get rest of the tests to work.

Future days - DSpace 7 Angular

Future days - Analyzer.atmire.com work

Future Days - Productivity

Future days - Jekyll http://bram-atmire.github.io/ site

Future Days - Atmire.com work

Investigate and work on search engine optimization (SEO) for the main atmire.com website.

Future Days - Learning just for learning

Sustainability challenge - Finish before Christmas

If I continue like October, I could hit day 68 by end of October and day 98 by end of November.