kekeh / angular-mydatepicker

Angular datepicker and date range picker :date:
https://kekeh.github.io/angular-mydatepicker/
MIT License
1 stars 11 forks source link

Angular 9 Test issue #61

Closed Romko775 closed 3 years ago

Romko775 commented 3 years ago

Hello @kekeh, I impressed with your datepicker, but my tests are failing with this

Chrome Headless 85.0.4183.102 (Linux x86_64) SomeComponent should create FAILED
        Error: Export of name 'angular-mydatepicker' not found!
            at cacheMatchingLocalNames (http://localhost:9877/_karma_webpack_/vendor.js:53601:23)
            at resolveDirectives (http://localhost:9877/_karma_webpack_/vendor.js:53360:13)
            at elementStartFirstCreatePass (http://localhost:9877/_karma_webpack_/vendor.js:61231:27)
            at ɵɵelementStart (http://localhost:9877/_karma_webpack_/vendor.js:61276:9)
            at ProfileComponent_Template (ng:///ProfileComponent.js:151:9)
            at executeTemplate (http://localhost:9877/_karma_webpack_/vendor.js:52614:9)
            at renderView (http://localhost:9877/_karma_webpack_/vendor.js:52384:13)
            at renderComponent (http://localhost:9877/_karma_webpack_/vendor.js:53963:5)
            at renderChildComponents (http://localhost:9877/_karma_webpack_/vendor.js:52185:9)
            at renderView (http://localhost:9877/_karma_webpack_/vendor.js:52410:13)
        Error: Expected undefined to be truthy.
            at <Jasmine>
            at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/main.js:26384:27)
            at ZoneDelegate.invoke (http://localhost:9877/_karma_webpack_/polyfills.js:13770:30)
            at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhost:9877/_karma_webpack_/vendor.js:165144:43)

My code:

<input type="text" id="date" angular-mydatepicker
                 [formControlName]="'date'"
                 [options]="pickerOptions" #dateInput #dp="angular-mydatepicker" autocomplete="off"
                 (click)="toggleCalendar()">

Can you help me how to fix tests ?

kekeh commented 3 years ago

Not sure, but maybe you have to exclude angular-mydatepicker from the test.

kekeh commented 3 years ago

angular-mydatepicker is exported here: https://github.com/kekeh/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/angular-mydatepicker.input.ts#L41

Romko775 commented 3 years ago

Okay, thank you, I will try it

Romko775 commented 3 years ago

@kekeh Thank you! Your link helped.

Fix for me

@Directive({
  selector: '[angular-mydatepicker]',
  exportAs: 'angular-mydatepicker',
})
class DatepickerDirective {
}
...

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [SomeComponent, DatepickerDirective],