您好,我正在开发 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)
有人可以帮我调用我的模拟服务吗?任何帮助,将不胜感激。谢谢
嗨,我正在为我的 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)
在上面的方法中,第一个参数应该是事件。有人可以帮助我如何创建活动吗?任何帮助,将不胜感激。谢谢
我正在尝试用 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)angular ×1
angular-test ×1
angularjs ×1
css ×1
html ×1
jasmine ×1
javascript ×1
jquery ×1
typescript ×1
unit-testing ×1