Easy mocking in Angular for container components

Everybody how tried to write some tests for container ccomponents knows the pain of writing the mocks. This can be very time consuming, since you have to write Mock classes for each used components including inputs etc. The possibility of NO_ERRORS_SCHEMA should NOT be used, since it is suppressing ALL error messages concerning the schema. It is just an option to lead testing ad abdsurdum …

BUT I found a nice module which is a very nice solution: ng-mocks. Mocking a component is then a oneliner in the TestBed configuration:

import { MockComponent } from 'ng-mocks';

// ... 

      declarations: [
        TestedComponent,
        MockComponent(DependencyComponent),
      ]

String comparison failure

Expected “this is a string for 2.000 €” is not equal to “this is a string for 2.000 €”

If you are writing tests and have string comparisons done, it can be sometimes tricky. Common problems are:

  • character encoding, eg. UTF-8 vs. ISO 8859-15
  • whitespace or non-visible (in your editor) characters at the end/beginning
  • non-breaking space characters, eg. in the example above between amount and currency