1

I just updated RC3 to RC4 and now i get this error in my tests:

Error: overrideDirective is not supported in this implementation of TestComponentBuilder

In TestComponentBuilder inside @angular/core@2.0.0-rc.4/testing/test_component_builder.js i can see this declaration of the method

TestComponentBuilder.prototype.overrideDirective = function(componentType, from, to) {
    throw new Error('overrideDirective is not supported in this implementation of TestComponentBuilder.');
};

So now the question is: how do i override a directive?

Bolza
  • 1,904
  • 2
  • 17
  • 42

2 Answers2

1

Ok so it seems that they deliberatevely removed the feature without replacing it with something else as stated in this issue

So the only solution i found is to use a strange OverridingTestComponentBuilder that suddenly appeared in compiler/testing.

This is not ideal as from RC4 TestComponentBuilder should be imported from @angular/core/testing but it's a temporary fix waiting for them to sort this out.

Once you import the class you can use it just like you'd use TestComponentBuilder

import { OverridingTestComponentBuilder } from '@angular/compiler/testing'

beforeEach(inject([OverridingTestComponentBuilder], _tcb => {
    tcb = _tcb
}));

And all the override* methods should work nicely.

Bolza
  • 1,904
  • 2
  • 17
  • 42
1

The default Angular test providers should give you an OverridingTestComponentBuilder implementation for the TestComponentBuilder type by default. How are you setting up your test? (e.g. setBaseTestProviders? Using the lists provided by Angular should fix your problem. Here's an example: https://github.com/juliemr/ng2-test-seed/blob/master/karma-test-shim.js#L84

Jmr
  • 12,078
  • 4
  • 39
  • 33