小编Nir*_*jan的帖子

如何使用多个参数调用 toHaveBeenCalledWith?

您好,我正在开发 Web 应用程序Angular JS。我正在使用框架编写单元测试用例Jasmine。我试图嘲笑一些服务。我无法使用多个参数调用服务。下面是我的单元测试代码。

it('update is allowed false', async(() => {
        let service = fixture.debugElement.injector.get(UserOnboardEndpointMock);
        spyOn(service, 'updateUser').and.callThrough();
        fixture.whenStable().then(() => {
            expect(service.updateUser).toHaveBeenCalledWith(jasmine.any(true,"101"));
        })
    }));
Run Code Online (Sandbox Code Playgroud)

下面是我的服务。

 updateUser<T>(event: boolean, userid: string): Observable<T>{
        var updateUserResult = { result: true } as any;
        return Observable.of<T>(updateUserResult);
    }
Run Code Online (Sandbox Code Playgroud)

我已尝试如下拨打服务电话,但没有成功。

expect(service.updateUser).toHaveBeenCalledWith(true,"101");
expect(service.updateUser).toHaveBeenCalledWith([true]["101"]);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我调用我的模拟服务吗?任何帮助,将不胜感激。谢谢

unit-testing jasmine angularjs

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

如何在 Angular 2 中为单元测试创​​建新事件?

嗨,我正在为我的 angular 代码编写单元测试用例。我正在尝试更新 gridview 中的文本框。下面是我的 gridview 代码。

<input *ngIf="editing[rowIndex + '-scopevalue']" class="inline-editor" autofocus (blur)="updateValue($event, 'scopevalue', value, rowIndex)" type="text" [value]="value" />
Run Code Online (Sandbox Code Playgroud)

下面的函数执行更新。

 updateValue(event, cell, cellValue, rowIndex) {
        this.editing[rowIndex + '-' + cell] = false;
        this.rows[rowIndex][cell] = event.target.value;
        this.rowsCache[rowIndex][cell] = event.target.value;
        this.scopeEdit = this.rows[rowIndex];
        this.updateScope();
    }
Run Code Online (Sandbox Code Playgroud)

在单元测试用例下面,我正在编写检查上面的代码。

 it('update scope name value', () => {
        var row = component.rows[0];
        let cell = 'scopevalue';
        let cellValue = row.scopevalue;
        let rowIndex = 0;
        component.updateValue('/bmw', cell, cellValue, rowIndex);
    });
Run Code Online (Sandbox Code Playgroud)

在上面的方法中,第一个参数应该是事件。有人可以帮助我如何创建活动吗?任何帮助,将不胜感激。谢谢

typescript karma-jasmine angular angular-test

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

更改下拉项目选择上的下拉按钮文本

我正在尝试用 HTML 和 CSS 开发下拉框列表。我试图在单击它时切换下拉框列表。当我选择某个项目时,它不会出现在下拉按钮中。

下面是我的代码。

function toggleItems() {
  $('.dropdown-menu').toggleClass('open');
}

function test() {
  var element = document.getElementById("flat-example-2");

  if ($(element).hasClass('on')) {
    element.classList.remove("on");
  } else {
    element.classList.add("on");
  }
}
Run Code Online (Sandbox Code Playgroud)
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  float: left;
  min-width: 150px;
  max-height: 600px;
  overflow-x: visible;
  overflow-y: visible;
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  background-color: #FFFFFF;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0;
  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  box-shadow: …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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