From 1f56d75fe41096d584782794e957ca9d144ef5bf Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Wed, 25 Sep 2024 15:00:07 +0300 Subject: [PATCH] fix(angular): race condition when `[maskitoOptions]` are changed before long element predicate is resolved --- projects/angular/src/lib/maskito.directive.ts | 4 ++-- .../angular-predicate/angular-predicate.cy.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/projects/angular/src/lib/maskito.directive.ts b/projects/angular/src/lib/maskito.directive.ts index 2e6ee524a..fafb58e5a 100644 --- a/projects/angular/src/lib/maskito.directive.ts +++ b/projects/angular/src/lib/maskito.directive.ts @@ -48,9 +48,9 @@ export class MaskitoDirective implements OnDestroy, OnChanges { const predicateResult = await elementPredicate(elementRef); // eslint-disable-next-line unicorn/consistent-destructuring - if (this.elementPredicate !== elementPredicate) { + if (this.elementPredicate !== elementPredicate || this.options !== options) { // Ignore the result of the predicate if the - // maskito element has changed before the predicate was resolved. + // maskito element (or its options) has changed before the predicate was resolved. return; } diff --git a/projects/demo-integrations/src/tests/component-testing/angular-predicate/angular-predicate.cy.ts b/projects/demo-integrations/src/tests/component-testing/angular-predicate/angular-predicate.cy.ts index cb42114a4..1d575f175 100644 --- a/projects/demo-integrations/src/tests/component-testing/angular-predicate/angular-predicate.cy.ts +++ b/projects/demo-integrations/src/tests/component-testing/angular-predicate/angular-predicate.cy.ts @@ -175,14 +175,12 @@ describe('@maskito/angular | Predicate', () => { cy.get('input').focus().type('12abc3').should('have.value', '12abc3'); }); - // TODO: uncomment in this PR https://github.com/taiga-family/maskito/pull/1608 - it.skip('enabling of the first mask should be skipped if [maskitoOptions] were changed during resolving of element predicate', () => { + it('enabling of the first mask should be skipped if [maskitoOptions] were changed during resolving of element predicate', () => { cy.smartTick(PREDICATE_RESOLVING_TIME, {fixture}); // predicate is resolved only once for digit cases cy.get('input').focus().type('12abc3').should('have.value', '12abc3'); }); - // TODO: uncomment in this PR https://github.com/taiga-family/maskito/pull/1608 - it.skip('only the last mask should be applied if [maskitoOptions] were changed during resolving of element predicates', () => { + it('only the last mask should be applied if [maskitoOptions] were changed during resolving of element predicates', () => { cy.smartTick(SWITCH_OPTIONS_TIME + PREDICATE_RESOLVING_TIME, {fixture}); // enough time to resolve element predicated for both cases cy.get('input').focus().type('12abc3').should('have.value', 'abc'); });