我是Jasmine的新手,我正在通过UI进行测试,因此在搜索输入字段中输入值并触发keyup事件后,将调用搜索功能,该功能已通过在不同点登录进行确认,但未触发API调用,即在搜索功能中。我必须使用await还是类似的方法?
dashboard.spec文件
> Loading data from '/content/musegan/scripts/../data/train_x_lpd_5_phr.npz'.
Saving data to shared memory.
tcmalloc: large alloc 6245990400 bytes == 0x26b6000 @ 0x7f97d2bea1e7 0x7f97d08e0a41 0x7f97d0943bb3 0x7f97d08e4937 0x5553b5 0x5a730c 0x503073 0x507641 0x504c28 0x502540 0x502f3d 0x507641 0x501945 0x591461 0x59ebbe 0x545068 0x506b39 0x502209 0x502f3d 0x506859 0x504c28 0x506393 0x634d52 0x634e0a 0x6385c8 0x63915a 0x4a6f10 0x7f97d27e7b97 0x5afa0a
./scripts/process_data.sh: line 5: 360 Killed python "$DIR/../src/process_data.py" "$DIR/../data/train_x_lpd_5_phr.npz"
从UI触发触发keyup事件的搜索功能:
beforeEach(() => {
inputElement = fixture.nativeElement.querySelector('input[name=search]');
inputElement.focus()
inputElement.value = '131420'
inputElement.dispatchEvent(new Event('input'));;
fixture.detectChanges();
keyUp().then(async () => {
expect(component.searchText).toEqual(inputElement.value)
});
});
it('should update the input', () => {
fixture.detectChanges();
console.log(component, 'component')
})
function keyUp() {
inputElement.dispatchEvent(new KeyboardEvent('keyup', { 'key': 'Space' }));
fixture.detectChanges();
inputElement.blur();
return fixture.whenStable();
}
答案 0 :(得分:0)
您正在beforeEach
中进行异步操作。为此,您应该使用一个回调函数,当所有异步工作完成后,该函数将被调用:
beforeEach((done) => {
promise.then(() => {
done();
});
}
此外,您可能不应该在设置函数(beforeEach)中(但在测试用例中)声明(期望)。