小编fir*_*baa的帖子

角单元测试:TypeError:无法读取未定义的属性“ root”

我正在Angular应用程序下进行单元测试。

我的角度版本是4.0.0

我的组件如下所示:

component.ts:

import { GdfaClientService } from '../../../service/gdfa-client.service';
import { SharedclientService } from '../../../service/sharedclient.service';
import { Client } from '../../model/client';
import { RouteNavigator } from '../../util/route-navigator';
import { Component, OnInit } from '@angular/core';
import {MonitoringService} from '../../../service/monitoring.service';
@Component({
  selector: 'app-queue-again',
  templateUrl: './queue-again.component.html',
  styleUrls: ['./queue-again.component.css'],
})
export class QueueAgainComponent implements OnInit {

  //-- variables --//
  showError = false;
  queueChoices = [];
  selectedQueue;
  selectedReason;
  requestInProgress = false;
  client: Client;
  errorMessage: string;
  queues: any;
  bankNotAllowed: boolean = false;

  constructor(private sharedclientService: SharedclientService, …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine testbed typescript angular

7
推荐指数
1
解决办法
2513
查看次数

Angular 5:ng build - -prod由于clean-css而失败:无法读取未定义的属性"line"

我的应用程序属于Angular 5.2.6

事情是正常的 ng serve

但是在运行时:ng build --prod在失败之前需要一段时间

这些错误似乎与clean-css操作有关:

错误跟踪:

 92% chunk asset optimization/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37
  if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) {
                      ^

TypeError: Cannot read property 'line' of undefined
    at originalPositionFor (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37:23)
    at originalMetadata (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:486:43)
    at intoTokens (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:240:75)
    at tokenize (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:74:10)
    at fromStyles (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:147:12)
    at fromString (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:48:10)
    at doReadSources (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:33:12)
    at readSources (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:24:10)
    at /home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/clean.js:99:12
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)
Run Code Online (Sandbox Code Playgroud)

它似乎在清洁CSS时失败了.

这是我的package.json:

{
  "name": "test",
  "version": …
Run Code Online (Sandbox Code Playgroud)

javascript typescript clean-css angular-cli angular

7
推荐指数
1
解决办法
1563
查看次数

Rxjs Websocket:如何添加标头

我正在使用 rxjs 在我的 Angular 应用程序中使用 websocket。

我像这样实例化它:我想添加一些标题:

myheader : "abcde"
Run Code Online (Sandbox Code Playgroud)

我是怎么做的?

这是我的代码:

import { BehaviorSubject, of, Subscription, Subject, Observable, NextObserver } from 'rxjs';

@Injectable()
export class WebsocketService  {

  openConnection() {
    this.close();
    const url = 'wss://echo.websocket.org';
    this.connection$ = webSocket({
      url, 
      openObserver: this.openObserver,
      closeObserver: this.closeObserver,
    });
    this.getmsg();

  }
}
Run Code Online (Sandbox Code Playgroud)

建议?

javascript websocket rxjs angular

7
推荐指数
1
解决办法
902
查看次数

不能在*ngFor:angular2中使用*ngIF

我正在使用来自服务的angular2和i'im绑定数据,问题是当我加载数据时我应该用id过滤它,这是我应该做的:

<md-radio-button
        *ngFor="#item of items_list"
        *ngIf="item.id=1"
        value="{{item.value}}" class="{{item.class}}" checked="{{item.checked}}"> {{item.label}}
</md-radio-button>
Run Code Online (Sandbox Code Playgroud)

这是数据:

[
  { "id": 1, "value": "Fenêtre" ,"class":"md-primary" ,"label":"Fenêtre" ,"checked":"true"},
  { "id": 2, "value": "Porte Fenêtre" ,"class":"" ,"label":"Porte Fenêtre" }

]
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我只想接受id = 1的数据,但我看到了这个错误:

EXCEPTION: Template parse errors:
Parser Error: Bindings cannot contain assignments at column 14 in [ngIf item.id=1] in RadioFormesType1Component@10:16 ("
        <md-radio-button
                *ngFor="#item of items_list"
                [ERROR ->]*ngIf="item.id=1"
                value="{{item.value}}" class="{{item.class}}" checked="{{item.check"): RadioFormesType1Component@10:16
Run Code Online (Sandbox Code Playgroud)

有什么建议一起使用ngif和ngfor?

json typescript angular2-directives angular2-services angular

6
推荐指数
3
解决办法
2万
查看次数

Angular 单元测试:失败:模块“DynamicTestModule”导入的意外值“DxTemplateHost”:添加@NgModule 注释

我正在为我的 Component 实施一个简单的单元测试。

  • 我导入了所有必要的东西:服务、RouterModuleTesting、FormsModule HttpModule ...

  • 请注意,我正在使用 DevExtreme Widgets。

但同样,我遇到了一些奇怪的错误:

错误说我应该在某处添加@NgModule 注释,但不清楚。

我的测试文件如下:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CustomersListComponent } from './customers-list.component';
// DevExtreme Module
import {DxTemplateHost} from 'devextreme-angular';
// Router Testing Module
import {RouterTestingModule} from '@angular/router/testing';
// Services and HTTM Module
import { CustomerService } from './../customer.service';
import {HttpService} from '../../../shared/service/http.service';
import {SessionService} from '../../../shared/service/session.service';
import {HttpModule} from '@angular/http';
// Forms Module (ngModel)
import {FormsModule} from '@angular/forms';
// Schemas(datasource error)
import {CUSTOM_ELEMENTS_SCHEMA} …
Run Code Online (Sandbox Code Playgroud)

unit-testing devexpress typescript karma-jasmine angular

6
推荐指数
2
解决办法
1万
查看次数

单元测试:即使添加到"提供者",也没有"InterceptableStoreFactory"的提供者

我正在Angular应用程序中进行单元测试,我正在使用TestBed方法,

我正在测试组件,所以每个spec文件都是这样的

import...
describe('AppComponent', () => {
// Importing dependecies
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports : [RouterTestingModule , HttpModule , FormsModule ],
            declarations: [AppComponent
            ],
            providers: [AUTH_PROVIDERS ,UserService, SharedclientService, RouteNavigator, JwtHelper, ReloadTokenService, ShopService
                , EnvVarsService, ProfileService, LocalStorageService, ApiVersionInterceptor, ApiTrackingInterceptor, MonitoringService ,
                { provide: 'LOCAL_STORAGE_SERVICE_CONFIG', useValue: userConfig } , TokenUtilService , HttpInterceptorService ,
                { provide: InterceptableStoreFactory, useClass: InterceptableStoreFactoryMock },ReloadTokenEventService , InterceptableStoreFactory

            ]

        }).compileComponents();
    }));
    // detecting changes every times
    beforeEach(() => {
        fixture = TestBed.createComponent(AppComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    // …
Run Code Online (Sandbox Code Playgroud)

unit-testing fixtures jasmine testbed angular

6
推荐指数
1
解决办法
1153
查看次数

无法运行由Elasticsearch引起的Sonar Server无法以root身份运行

我正在尝试安装SonarQube:我已按照这些步骤操作:

设置SOnarQube Tuto:在这里

总结一下:

  • 下载声纳并将其移动到 /opt/sonar
  • 将这些coonfig步骤添加到/opt/sonar/conf/sonar.properties :

    sonar.jdbc.username = sonar sonar.jdbc.password = sonar

sonar.jdbc.url = JDBC:MySQL的://本地主机:3306 /声纳了useUnicode =真的characterEncoding = UTF8&rewriteBatchedStatements =真useConfigs = maxPerformance

sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000
Run Code Online (Sandbox Code Playgroud)
  • 实施声纳作为服务:

sudo cp /opt/sonar/bin/linux-x86-64/sonar.sh /etc/init.d/sonar

sudo gedit /etc/init.d/sonar
Run Code Online (Sandbox Code Playgroud)

插入两个新行:

SONAR_HOME=/opt/sonar
PLATFORM=linux-x86-64
Modify the following lines:

WRAPPER_CMD="${SONAR_HOME}/bin/${PLATFORM}/wrapper"
WRAPPER_CONF="${SONAR_HOME}/conf/wrapper.conf"
Run Code Online (Sandbox Code Playgroud)

...

PIDDIR="/var/run"
Register as a Linux service:

sudo update-rc.d -f sonar remove
sudo chmod 755 /etc/init.d/sonar
sudo update-rc.d sonar defaults
Run Code Online (Sandbox Code Playgroud)

在这些步骤之后:我试图从以下方式运行Sonar:localhost:9000/sonar并且在执行之后:sudo /etc/init.d/sonar start `奇怪的是,它没有运行.

所以,当我运行`须藤/etc/init.d/sonar状态,我发现它去几秒钟后步骤,它抛出它日志文件,像下面的一些错误:

es.log:

2017.12.09 18:05:14 ERROR …
Run Code Online (Sandbox Code Playgroud)

linux elasticsearch sonarqube

6
推荐指数
2
解决办法
2万
查看次数

Angular 4:如何为所有文件生成代码覆盖率并为 Sonar 导出

我正在为我的 angular 应用程序实现代码覆盖率 taaks,以在 Sonarqube 中显示其结果。

我的karma.conf.js看起来像这样:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true …
Run Code Online (Sandbox Code Playgroud)

code-coverage typescript sonarqube karma-jasmine angular

6
推荐指数
0
解决办法
4435
查看次数

Angular 5:使用Angular-CLI 1.7.x进行ng build - -prod时,Lazy Loading无法正常工作

我在工作:

  • Angular:5.2.6
  • Angular-CLI:1.7.x

我在我的应用程序下有这个路由文件(我有一些延迟加载模块):

const homeRoutes: Routes = [
  {
    path: 'home', component: HomeComponent,
    children: [
        ....
      {
        path: 'admin',
        loadChildren: 'app/home/admin/admin.module#AdminModule',
        canActivate: [AuthGuardAdmin]
      },
    ]
  },
];

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(homeRoutes)
  ],
  exports: [
    RouterModule
  ],
  declarations: []
})
export class HomeRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

运行ng服务,延迟加载不起作用,我得到这个错误:

>     core.js:1448 ERROR Error: Uncaught (in promise): TypeError: undefined is not a function
>     TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)

有些谷歌搜索我被告知改变我的懒加载像这样:

  {
    path: 'admin',
    loadChildren: ()=> AdminModule, …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular2-routing angular-cli angular

6
推荐指数
1
解决办法
1872
查看次数

使用 Chrome 无头和 Karma 进行 Angular 单元测试

我正在使用 Chrome-Headless 通过Karma运行我的Angular 7单元测试项目

它似乎不稳定,因为在运行几十个规范时,在没有完成所有测试的情况下在任何测试中随机中断

我不知道这是否是内存的问题,是 chrome 本身的业力问题..

我的 karma.conf :

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
var process = require('process');

module.exports = function (config) {

  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      reports: [ 'html', 'lcovonly' …
Run Code Online (Sandbox Code Playgroud)

javascript karma-runner karma-jasmine angular google-chrome-headless

6
推荐指数
1
解决办法
6725
查看次数