allianz / ng-aquila

Angular UI Component library for the Open Insurance Platform
https://allianz.github.io/ng-aquila/
Other
209 stars 36 forks source link

[nx-word, nxAutoResize] Missing canvas 2d context in environments with incomplete DOM implementation leads to error #56

Closed cuddlecake closed 1 year ago

cuddlecake commented 1 year ago

nx-word, nxAutoResize

Both of these directives use canvas to measure the effective width of the current input. This fails in environments that use an incomplete implementation of DOM, which affects users of jest with jsdom.

Currently, testing components that use nx-word or nxAutoResize requires either mocking nx-word, canvas, or installing a package like node-canvas.

This probably also affects server side rendering with Angular Universal, although I did not test that yet.

🎯 Goals

Make usage of nx-word and nxAutoResize less frustrating by handling the width calculation in a type safe manner. I.e. check if the context returned from canvas.getContext('2d') is null instead of asserting it as non-nullable, and act accordingly to prevent runtime errors during width calculation.

yd-allianz commented 1 year ago

Hi @cuddlecake

thanks for reporting. We'll have to check how we can improve this logic. We'll let you know about the outcome.

Phil147 commented 1 year ago

Hi @cuddlecake the issue should be fixed in 16.6.0