Bram's Dev Blog

home

100 Days of Code Day 66 - More Testing

29 Oct 2018

toBeTruthy()

Yesterday, I was wondering what truthy meant.

Truthy and Falsy: When All is Not Equal in JavaScript made it very clear. tl;dr

toBe(true) vs toBeTruthy() vs toBeTrue() on Stackoverflow puts this subtle difference into the context of the Jasmine matchers.

Should the component that we are testing be declared in the testbed or not?

In tutorials like this one, I’m always seeing that the component that is being tested, is included in the declarations of the test bed. However, in the DSpace 7 Browse By component that doesn’t seem to be the case and I wonder why.

Setup with module imports notes that either the component is already declared in one of your imports, or you declare it yourself in the spec you are writing. But I would tend to think that your testbed will always somehow need the code you wrote in the actual component file, so I would think you would always want to import it rather than declare it.

Testbed .compileComponents() and splitting beforeEach into sync & async methods.

In an Angular CLI project, you don’t need to call .compileComponents() for a testbed. However, as we’re not (yet) on the Angular CLI structure in DSpace 7, you still have to do it to make sure your external .html and .css files are present.

This also relates to the reason why beforeEach methods are split up in an async and a sync one:

Source - Angular.io testing guide

Bringing over the ngx-translate example test code into DSpace 7

Yesterday I already mentioned that How to unit test a component with TranslateService and the translate pipe? featured a whole discussion of what and how to mock for TranslateService. In one of the last replies in the thread, the developer behind ngx-translate responded by adding a spec to his example app.

I made progress, and added my current test file to the pull request, however, it is still failing against dependency injections at the moment.

Day 66 Plan

Solve the dependency injection problems for the tests

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.