From 2583074f8e7e5d747d8b7182a66cccbcb35d7fe4 Mon Sep 17 00:00:00 2001 From: Kordrad Date: Wed, 10 Jul 2024 12:41:26 +0200 Subject: [PATCH] test(disabled.directive): fix tests --- jest.config.ts | 4 +++ .../files/disabled/disabled.directive.spec.ts | 30 +++++++++++++++++-- .../files/disabled/disabled.directive.ts | 4 +-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 4a27584..13fb0a8 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -12,6 +12,10 @@ export default { coverageProvider: 'v8', moduleNameMapper: { '^@ng-zen/cli/(.*)': '/projects/cli/src/$1', + '^ng-zen/components/(.*)': + '/projects/cli/schematics/components/files/$1', + '^ng-zen/directives/(.*)': + '/projects/cli/schematics/directives/files/$1', }, preset: 'jest-preset-angular', testEnvironment: 'jsdom', diff --git a/projects/cli/schematics/directives/files/disabled/disabled.directive.spec.ts b/projects/cli/schematics/directives/files/disabled/disabled.directive.spec.ts index def02b1..c3b2719 100644 --- a/projects/cli/schematics/directives/files/disabled/disabled.directive.spec.ts +++ b/projects/cli/schematics/directives/files/disabled/disabled.directive.spec.ts @@ -1,8 +1,34 @@ +import { Component } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; + import { ZenDisabledDirective } from './disabled.directive'; +import { ZenHostDirective } from './index'; + +@Component({ + template: ``, + hostDirectives: [ZenHostDirective], + standalone: true, +}) +class ZenDisabledComponent {} describe('ZenDisabledDirective', () => { - it('should create an instance', () => { - const directive = new ZenDisabledDirective(); + let component: ZenDisabledComponent; + let directive: ZenDisabledDirective; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ZenDisabledComponent], + }).compileComponents(); + + const fixture: ComponentFixture = + TestBed.createComponent(ZenDisabledComponent); + component = fixture.componentInstance; + directive = fixture.debugElement.injector.get(ZenDisabledDirective); + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); expect(directive).toBeTruthy(); }); }); diff --git a/projects/cli/schematics/directives/files/disabled/disabled.directive.ts b/projects/cli/schematics/directives/files/disabled/disabled.directive.ts index c2d2e05..54725f6 100644 --- a/projects/cli/schematics/directives/files/disabled/disabled.directive.ts +++ b/projects/cli/schematics/directives/files/disabled/disabled.directive.ts @@ -18,12 +18,12 @@ import { computed, Directive, HostBinding, model } from '@angular/core'; export class ZenDisabledDirective { /** Model for the disabled state of the checkbox. */ - readonly disabled = model(false, { + disabled = model(false, { alias: 'zenDisabled', }); /** @ignore */ - readonly disabledBoolean = computed(() => + disabledBoolean = computed(() => [true, 'true', ''].includes(this.disabled()) );