选择选项后,NG-SELECT集成测试将失败

时间:2018-09-25 12:01:19

标签: angular angular-components angular-ngselect

我正在努力为自定义ng-select组件编写适当的测试。该组件正在按预期工作,但是我很难尝试对其进行测试,因此找不到解决方案。尝试了多种方法来解决该错误,但是选择选项后,我一直坚持struct Data:Decodable { var var_image: String? var tblogdescription : String? var var_blogtitle: String? init(blogdata:[String:Any]) { self.var_blogtitle = blogdata["var_blogtitle"] as? String self.tblogdescription = blogdata["tblogdescription"] as? String self.var_image = blogdata["var_image"] as? String } } 。任何帮助将不胜感激。

Error: 1 timer(s) still in the queue.

Component

@Component({ selector: 'dp-auto-complete', templateUrl: './auto-complete.component.html', styleUrls: ['./auto-complete.component.scss'], providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => AutoCompleteComponent), multi: true } ] }) export class AutoCompleteComponent implements OnInit, OnDestroy, ControlValueAccessor { @Input() apiMethod: string; @Input() placeholder: string; @Input() labelProps: string[]; @Input() callApi = true; @Output() selectedItem = new EventEmitter<any>(); loading = false; selected: any; disabled: boolean; items$: Observable<any>; input$ = new BehaviorSubject(''); constructor(private api: ApiService) { } ngOnInit() { this.placeholder = this.placeholder || 'Select items'; if (this.callApi) { this.onSearch(); } } ngOnDestroy() { this.input$.complete(); } setDisabledState(isDisabled: boolean) { this.disabled = isDisabled; } registerOnTouched() { } registerOnChange(fn: any) { this.propagateChange = fn; } writeValue(value: any = null) { this.selected = value; } private propagateChange = (_: any) => {}; onSearch() { this.items$ = concat( of([]), this.input$.pipe( debounceTime(300), tap(() => this.loading = true), switchMap(term => this.callService(term).pipe( catchError(() => of([])), tap(() => this.loading = false) )) ) ); } private callService(term: string) { return this.api[this.apiMethod](term).pipe(map((item: any) => item.results)); } propagateSelected() { this.propagateChange(this.selected); this.selectedItem.emit(this.selected); } }

Template

<ng-select [items]="items$ | async" [loading]="loading" placeholder="{{placeholder}}" [typeahead]="input$" [(ngModel)]="selected" (change)="propagateSelected()" [disabled]="disabled"> <ng-template ng-label-tmp ng-option-tmp let-item="item"> <div *ngFor="let label of labelProps" class="d-inline"> {{item[label]}} </div> </ng-template> </ng-select>

Integration TEST

屏幕截图 screenshot from 2018-09-25 13-23-02

我可以看到已选择该值,并且也已在该组件上设置了该值,但是我不知道为什么队列中有1个计时器以及如何解决它。

0 个答案:

没有答案