小编cod*_*pic的帖子

JavaScript单元测试的代码覆盖范围是什么?

我使用伊斯坦布尔代码覆盖AngularJS项目中的单元测试.有4种类型的报道,它们是

  • 声明
  • 功能
  • 线

声明,功能和线路都没问题,但我不明白"分支"是什么.什么是分支?

javascript unit-testing code-coverage istanbul

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

jQuery没有在bootstrap-sass中定义

我使用angular-cli引导了Angular 2应用程序.在我决定使用bootstrap模态之前,一切都很容易.我只是复制了从不使用angular-cli的其他项目中打开模态的代码.我将jquery和bootstrap依赖项添加到angular-cli.json文件中的脚本中.jQuery在项目中被识别,但是当我尝试this.$modalEl.modal(options)在角度组件内运行时,我得到一个错误jQuery is not defined.

实际上jQuery被导入到项目中但作为全局$.我做了一些挖掘,显然bootstrap期望jQuery作为'jQuery'变量传递给它.它没有给老鼠的屁股$.

我可以像在其他项目中一样jQuerywebpack.config.js文件中公开变量:(为简洁起见省略了很多代码)

var jQueryPlugin = {
  $: 'jquery',
  jquery: 'jquery',
  jQuery: 'jquery'
}

exports.root = root;

exports.plugins = {
  globalLibProvider: new webpack.ProvidePlugin(webpackMerge(jQueryPlugin, {
    svg4everybody: 'svg4everybody/dist/svg4everybody.js'
  }))
}
Run Code Online (Sandbox Code Playgroud)

angular-cli开发团队决定不让其他开发者干涉webpack配置文件.多谢你们!非常考虑你.

我已经尝试将jQuery直接导入到Angular组件中,并在这里提到了一些其他的东西https://github.com/angular/angular-cli/issues/3202(将进口添加到vendor.ts文件然后添加vendor.ts到angular-cli.json中的scripts数组但没有任何效果.

说实话,我很生气这样一个微不足道的问题,比如在angular-cli中增加jquery依赖性bootstrap就是这样一个雷区.

你有没有处理类似的问题?

jquery bootstrap-sass webpack angular-cli angular

8
推荐指数
1
解决办法
1135
查看次数

C# 8.0 - 不能使用默认接口实现

我最近读到有关 C# 8.0 具有接口默认实现的信息,所以我进入了我的项目并尝试了它,但我遇到了一个错误。Target runtime doesn't support default interface implementation. 有没有办法解决这个问题?

string CommandName { get => CommandName.ToUpperInvariant(); }
Run Code Online (Sandbox Code Playgroud)

编辑 我正在使用Console

c# interface default-implementation c#-8.0

8
推荐指数
1
解决办法
4877
查看次数

'Actions'类型中不存在属性'payload'

我是TypeScript和Visual Studio Code的新手.我收到以下错误:

*[ts] Property 'payload' does not exist on type 'Actions'.

我的代码:

action.ts文件:

  import { Action } from '@ngrx/store';
  import { Item } from '../models/list';

  export class AddBookAction implements Action {
      type = ActionTypes.ADD_BOOK;

      constructor(public payload: Item) { }
  }

  export type Actions = AddBookAction;
Run Code Online (Sandbox Code Playgroud)

reducer.ts

import * as list from 'action';

export function reducer(state = initialState, action: list.Actions): State {

switch (action.type) {
    case list.ActionTypes.LOAD: {
      return Object.assign({}, state, {
        loading: true
      });
    }

    case list.ActionTypes.LOAD_SUCCESS: {
      const …
Run Code Online (Sandbox Code Playgroud)

typescript visual-studio-code ngrx

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

在 Angular 应用程序中使用 Jasmine 测试 SignalR 的问题

我这里有一个严重的问题。我的应用程序依赖于 SignalR 功能,但因此我无法编写单元测试。我是测试框架的新手,只在简单的情况下使用过 Jasmine。事实证明 SignalR 对我来说是一个太大的挑战,但我需要了解如何成功测试它。这是我的 CommsApp.ts 文件 [打字稿]:

/// <reference path="References.ts" />
var commsAnimationsModule = angular.module('forge.communications.animations', ['ngAnimate']);
var commsDirectivesModule = angular.module('forge.communications.directives', []);
var commsServicesModule = angular.module('forge.communications.services', []);
var commsFiltersModule = angular.module('forge.communications.filters', []);

var commsApp = angular.module('forge.communications.CommsApp',
    [
        'ngRoute',
        'ngAnimate',
        'cfValidation',
        'ui.bootstrap',
        'forge.communications.animations',
        'forge.communications.directives',
        'forge.communications.services',
        'forge.communications.filters',
        'angularFileUpload',
        'timeRelative'
    ]);

commsApp.config(function ($routeProvider: ng.route.IRouteProvider, $locationProvider: any) {

        $locationProvider.html5Mode(true);
        $routeProvider.
            when('/scheduled-messages', {
                templateUrl: '/forge/CommsApp/js/Controllers/ScheduledMessageList/ScheduledMessageList.html',
                controller: 'ScheduledMessageListController'
            }).
            when('/geotriggered-messages', {
                templateUrl: '/forge/CommsApp/js/Controllers/GeoMessageList/GeoMessageList.html',
                controller: 'GeoMessageListController'
            }).
            when('/scheduled-message/create', {
                templateUrl: '/forge/CommsApp/js/Controllers/CreateScheduledMessage/CreateScheduledMessage.html',
                controller: 'CreateScheduledMessageController'
            }).
            when('/scheduled-message/edit/:id', { …
Run Code Online (Sandbox Code Playgroud)

javascript signalr angularjs karma-jasmine

5
推荐指数
1
解决办法
2078
查看次数

如何使用Angular Material Datepicker禁用特定日期?

我想在Angular Material Datepicker组件中禁用周末和特定日期。

我怎样才能做到这一点?

app.component.html:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

package.json:

"dependencies": {
    "@angular/animations": "^5.1.3",
    "@angular/cdk": "^5.0.3",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/material": "^5.0.3",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
Run Code Online (Sandbox Code Playgroud)

angular-material angular

5
推荐指数
1
解决办法
6529
查看次数

Ngxs-呼叫Angular服务:良好做法?

当我使用ngxs我的应用程序应该做什么时:

  • 我的组件调用服务,并且该服务调度一个操作,其结果为有效载荷?
  • 我的组件派遣了一项行动,而我所在的州致电了该服务?

redux angular ngxs

5
推荐指数
2
解决办法
1290
查看次数

在 Ubuntu 16.04 上创建解决方案文件时,JetBrains Rider 挂起

在 Ubuntu 16.04 上创建解决方案文件时,JetBrains Rider 无限期挂起。已经重新启动了 Rider 和我的系统。

ubuntu-16.04 rider

5
推荐指数
1
解决办法
1239
查看次数

单元测试 NgRx 效果以确保服务方法被调用 - 不起作用

我正在使用 NgRx ^7.0.0 版本。这是我的 NgRx 效果类:

import { Injectable } from '@angular/core';
import { ApisService } from '../apis.service';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { ApisActionTypes, ApisFetched } from './apis.actions';
import { mergeMap, map } from 'rxjs/operators';

@Injectable()
export class ApisEffects {

  constructor(private apisS: ApisService, private actions$: Actions) { }

  @Effect()
  $fetchApisPaths: Observable<any> = this.actions$.pipe(
    ofType(ApisActionTypes.FetchApisPaths),
    mergeMap(() =>
      this.apisS.fetchHardCodedAPIPaths().pipe(
        map(res => new ApisFetched(res))
      )
    )
  );
}
Run Code Online (Sandbox Code Playgroud)

这是一个简单的测试。如您所见,它应该失败,但总是通过。我在 StackOverflow 上遵循了类似的问题如何对这种效果进行单元测试(使用 …

unit-testing jestjs ngrx ngrx-effects angular

5
推荐指数
1
解决办法
3341
查看次数

开玩笑-使用spyOn函数时,请确保未调用该间谍程序

从Jest注意:注意:默认情况下,jest.spyOn也调用spied方法。

在我的Angular组件中。

ngAfterViewInit(): void {
  this.offsetPopoverPosition();
}
Run Code Online (Sandbox Code Playgroud)

在我的规格中:

it('ngAfterViewInit() method should call offsetPopoverPosition() method', () => {
    const mockListener = jest.spyOn(cmp, 'offsetPopoverPosition');
    const spy = mockListener.mockImplementation(() => {
      console.log('in the mock');
    });

    cmp.ngAfterViewInit();
    expect(spy).toHaveBeenCalled();
  });
Run Code Online (Sandbox Code Playgroud)

简单。然而,原始功能仍在被调用。我检查了Jest 23.x文档:https : //jestjs.io/docs/en/23.x/jest-object#jestspyonobject-methodname https://jestjs.io/docs/en/23.x/mock-function -api#mockfnmockimplementationfn

互联网上的例子很少,但我无法阻止开玩笑地调用原始offsetPopoverPosition()方法。

有任何想法吗?

我交叉链接到Jest github问题,由于某种原因该问题未解决而已关闭。

开玩笑spyOn()调用实际函数,而不是模拟

javascript jestjs angular

5
推荐指数
1
解决办法
1389
查看次数