ckeditor5-angular icon indicating copy to clipboard operation
ckeditor5-angular copied to clipboard

Problem with testing the component with jest

Open FERNman opened this issue 4 years ago • 7 comments

Hey there!

We're using this package in combination with jest as our testing framework. Because jest and ts-jest can't yet handle es modules, it is not possible to run unit tests. The only reason for that is the included CKEditor watchdog, which we don't actually need. Is there a way to remove this dependency and make it optional?

I was not able to find an easy way to set up ts-jest in a way that allows using es modules, and I'd like to avoid pulling in babel just for those few tests.

FERNman avatar Jul 07 '20 12:07 FERNman

cc @ma2ciek

FilipTokarski avatar Jul 08 '20 13:07 FilipTokarski

Hi!

I'm aware that currently, it's not possible to make it an optional dependency. The Watchdog feature was built-in into the component so it can restart the editor inside the component, which can't be done from the outside.

We'll try to merge the Watchdog to the ckeditor5-angular bundle in the future since this external import causes some problems from time to time.

An external import would make sense here but we chose the direct import from the ckeditor5-angular package as we weren't aware of such problems :/

ma2ciek avatar Jul 14 '20 13:07 ma2ciek

I'm marking it as a bug, though, ideally, it could be fixed on the jest's side.

ma2ciek avatar Jul 14 '20 13:07 ma2ciek

any update on it?

sireaev avatar Aug 07 '20 14:08 sireaev

Any updates on this issue?

csirwin avatar Dec 18 '20 13:12 csirwin

Hey, are there any plans on fixing this issue? We wanted to integrate your editor into our application, but sadly our tests fail because of this watchdog part. It would be really nice if this would get fixed, in the near future 😃

flaver12 avatar Mar 16 '21 12:03 flaver12

So for anyone interested in testing CKEditor 5 in Jest – you should be able to configure Jest to transpile CKEditor 5 from node_modules dir and stub its SVG and CSS files. I've posted this on SO as well.

But this is if you really need to load the whole editor into the test, which might be not so optimal. The other solution would be to use Jest's module mapper to entirely mock the CKEditor inside UI tests.

jodator avatar Apr 22 '21 14:04 jodator