Unfortunately, there are some issues as well. First, there are different packages required depending on a browser. There is something wrong with the one for Opera – the launcher keeps opening 3 instances of the browser, stating that it failed twice. Second, in Firefox there is a distracting stack trace right below tests which failed, which doesn’t point well to a place in my code:
Karma requires some configuration in an extra file, but unfortunately I won’t elaborate on it here. I just copied that config from the official Angular 2 application template, replaced Chrome (which I don’t have) with Firefox/Opera and adjusted paths. What was confusing to me was the fact that Karma seems to launch browsers with default settings, so for example my custom keyboard shortcut for displaying Dev Tools didn’t work. Just like the TypeScript compiler, Karma offers a watch mode – when a source file changes, it reruns its task. Currently there isn’t much to test, but I’ve made a temporary stub service for getting categories – there is no database nor server at all yet, so when I add it and update the service, a test will be beneficial.
In the context of Angular, the above refers to testing ‘pure’ classes. However, it’s also possible to test components – we can manipulate them and check whether a template reacts correctly. Seems cool, but I’ll rather skip it for now, because there are some higher priorities.