簡體   English   中英

Angular Angular 從 v7 升級到 v8 后出現 Karma 錯誤

[英]Angular Karma error after upgrading Angular from v7 to v8

我剛剛使用ng update將我的 Angular v7 項目更新為 v8。 我已經完成了所有步驟,並且項目構建良好。 但是,當我運行ng test時,我現在收到以下錯誤(對於我的所有組件)

    Failed: Template parse errors:
    'my-date-picker' is not a known element:
    1. If 'my-date-picker' is an Angular component, then verify that it is part of this module.
    2. If 'my-date-picker' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <h3>A date picker for selecting a single date of the year</h3>
    <div style="width:100px">
            [ERROR ->]<my-date-picker></my-date-picker>
    </div>
    <hr />
    "): ng:///DynamicTestModule/DatePickerExampleComponent.html@4:4
    Can't bind to 'value' since it isn't a known property of 'my-date-picker'.
    1. If 'my-date-picker' is an Angular component and it has 'value' input, then verify that it is part of this module.
    2. If 'my-date-picker' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
    3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("

這些用於在升級之前工作。

組件已聲明..

beforeEach(async(() => {
  TestBed.configureTestingModule({      
    declarations: [DatePickerExampleComponent],      
  })
  .compileComponents();
}));

並且存在於 app.module 聲明中。

我有以下開發部門

"devDependencies": {
            "@angular-devkit/build-angular": "~0.803.29",
            "@angular-devkit/build-ng-packagr": "~0.803.29",
            "@angular/cli": "~8.3.29",
            "@angular/compiler-cli": "~8.2.14",
            "@angular/language-service": "~8.2.14",
            "@types/cypress-image-snapshot": "^3.1.5",
            "@types/jasmine": "~2.8.8",
            "@types/jasminewd2": "^2.0.8",
            "@types/jest-image-snapshot": "^4.3.0",
            "@types/node": "^8.9.5",
            "codelyzer": "^5.0.1",
            "concurrently": "^6.2.0",
            "cypress": "7.4.0",
            "cypress-image-snapshot": "^4.0.1",
            "jasmine-core": "~2.99.1",
            "jasmine-spec-reporter": "~4.2.1",
            "karma": "~4.0.0",
            "karma-chrome-launcher": "~2.2.0",
            "karma-coverage-istanbul-reporter": "~2.0.1",
            "karma-jasmine": "~1.1.2",
            "karma-jasmine-html-reporter": "^0.2.2",
            "ng-packagr": "^5.4.0",
            "protractor": "~5.4.0",
            "shx": "^0.3.2",
            "ts-node": "^7.0.1",
            "tsickle": "^0.37.0",
            "tslib": "^1.14.1",
            "tslint": "~5.11.0",
            "typescript": "~3.5.3",
            "wait-on": "^5.3.0"
        }

有任何想法的人嗎?

您要么在測試模塊的聲明中重新聲明您的組件,要么導入包含您的組件的模塊

beforeEach(async(() => {
  TestBed.configureTestingModule({      
    declarations: [DatePickerExampleComponent,YourDatePickerHere],      
  })
  .compileComponents();
}));

或者

beforeEach(async(() => {
  TestBed.configureTestingModule({      
    declarations: [DatePickerExampleComponent],
    imports:[ModuleWithYourDatePickerComponent]      
  })
  .compileComponents();
}));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM