Skip to content

Commit

Permalink
fix(angular): Jest throws `Class constructor DefaultValueAccessor can…
Browse files Browse the repository at this point in the history
…not be invoked without 'new'` (#232)
  • Loading branch information
waterplea authored Mar 31, 2023
1 parent 4c1033f commit 5089612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: ./.github/actions/nodejs

- name: Run tests
run: npx nx run-many --target test --all
run: npx nx run-many --target test --all --coverage

- uses: codecov/codecov-action@v2
with:
Expand Down
21 changes: 13 additions & 8 deletions projects/angular/src/lib/maskito.cva.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ import {MASKITO_DEFAULT_OPTIONS, MaskitoOptions, maskitoTransform} from '@maskit
@Directive({
selector: 'input[maskito], textarea[maskito]',
providers: [
DefaultValueAccessor,
{
provide: NG_VALUE_ACCESSOR,
multi: true,
useExisting: MaskitoCva,
useExisting: DefaultValueAccessor,
},
],
host: {
'(input)': '$any(this)._handleInput($event.target.value)',
'(blur)': 'onTouched()',
'(compositionstart)': '$any(this)._compositionStart()',
'(compositionend)': '$any(this)._compositionEnd($event.target.value)',
'(input)': '$any(this.accessor)._handleInput($event.target.value)',
'(blur)': 'accessor.onTouched()',
'(compositionstart)': '$any(this.accessor)._compositionStart()',
'(compositionend)': '$any(this.accessor)._compositionEnd($event.target.value)',
},
})
export class MaskitoCva extends DefaultValueAccessor {
export class MaskitoCva {
@Input()
maskito: MaskitoOptions = MASKITO_DEFAULT_OPTIONS;

override writeValue(value: unknown): void {
super.writeValue(maskitoTransform(String(value ?? ''), this.maskito));
constructor(readonly accessor: DefaultValueAccessor) {
const original = accessor.writeValue.bind(accessor);

accessor.writeValue = (value: unknown) => {
original(maskitoTransform(String(value ?? ''), this.maskito));
};
}
}

0 comments on commit 5089612

Please sign in to comment.