Ad

How To Test A Component With Froala Editor In Karma For Angular?

I am using Froala Editor in my component. The editor is working fine when I run the website. But, the spec.ts file is generating this error.

TypeError: this.$element.froalaEditor is not a function

Any solution?

The onAddPost function is getting covered, no problems with that. But, the test case is failing because of the error regarding Froala editor itself.

Ad

Answer

So, as i see you do not use template of component in your test, so you can just remove FroalaEditorModule, FroalaViewModule from imports, and add template override for your component, like:

TestBed.configureTestingModule({
   ....
})
.compileComponents()
.overrideComponent(PostsAddComponent, {
    set: {
        template: ""
    }
});

Since your component won't have template, you won't use froala components & directives, and it won't access this global script and error should disappear. Hope that helps.

Ad
source: stackoverflow.com
Ad