我有一個用angular-cli創建的基本AngularJS2項目。我從新創建的項目開始。在app.component.ts
,我存儲日期:ng2日期管道格式化觸發'業餘測試中沒有本地數據'錯誤
theDate = new Date();
我使用日期管顯示它:
{{theDate | date}}
日期顯示正確和如預期格式化。但是,如果我跑ng test
,我得到以下錯誤:
Failed: Error in ./AppComponent class AppComponent - inline template:4:3 caused by: No locale data has been provided for this object yet.
[email protected]_modules/karma-intl-shim/lib/shim.js:11:1866
[email protected]_modules/karma-intl-shim/lib/shim.js:11:8835
[email protected]_modules/karma-intl-shim/lib/shim.js:11:8335
失敗的測試是:
it('should render title in a h1 tag', async(() => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));
package.json
:
"karma-intl-shim": "^1.0.3"
karma.conf
:
module.exports = function (config) {
config.set({
...
frameworks: ['jasmine', 'angular-cli', 'intl-shim'],
plugins: [
require('karma-intl-shim'),
...
] ...
備註:
- 角(CLI) 「1.0.0-beta.16」
- 我切換到
PhantomJS
爲了方便但同樣具有Chrome
發生。 - 我確實執行了
npm install --save
來安裝依賴關係。
爲了方便讀者閱讀,項目存儲在here。
缺失的是什麼?謝謝。
我karma.conf.json文件中包含的文件:[{ 模式: './src/test.ts',眼睜睜地看着:假} ],它應該是更新文件:[{ 模式:' ./ src/test.ts',看過:false},'./node_modules/Intl/locale-data/jsonp/en-US.js' ] –
@NaveedAhmed,你可能想檢查我的答案在這裏..http:/ /stackoverflow.com/questions/43182840/no-locale-data-error-in-karma-test-using-phantomjs/43228904#43228904 – N0mi