小编Fli*_*lix的帖子

如何检查我的元素是否已集中在角度4的单元测试中?

我有以下功能进行单元测试.我在元件中采用了带有视图子元素的文本框元素,在测试中我需要在setTimeout()调用之后测试我的文本框是否有焦点.

 @ViewChild('searchInput') searchInput: ElementRef;
function A(show) {
        const self = this;
        if (show) {
            this.xyz= true;
            setTimeout(function () {
                self.searchInput.nativeElement.focus();
            }, 0);
        } else {
            self.xyz= false;
            self.abc = '';
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试的测试用例:

it('textbox get focus toggleSearch', async(() => {
        let el: DebugElement;

        component.toggleSearch(true);
        el = fixture.debugElement.query(By.css('#search-input-theme'));
        let native: HTMLElement = el.nativeElement;
        spyOn(native,'focus');
        fixture.whenStable().then(() => {
            expect(native.focus).toHaveBeenCalled();
        });
    }));
Run Code Online (Sandbox Code Playgroud)

angular2-testing angular

7
推荐指数
2
解决办法
5019
查看次数

如何使用rxfire和rxjs(OR查询)加入两个Firestore查询

我们的目标很简单:将两个公司的FireStore查询利用rxjs,rxfire以及rnfirebase反应机库.

我读过多教程1,2上加入查询,但他们都失败,不同的错误.

//Simple test for collectionData
import { collectionData } from 'rxfire/firestore';

this.myQuery = this.props.docRef.collection(`messages`).where('read', 'array-contains', this.props.me.uid)
collectionData(this.myQuery, 'id').subscribe(docs => console.log(docs))
//Fails with error: this._next is not a function.
Run Code Online (Sandbox Code Playgroud)

或者,

this.publicQuery = this.props.docRef.collection('messages').where('public', '==', true) 
this.myQuery = this.props.docRef.collection(`messages`).where('read', 'array-contains', this.props.me.uid)
const myQuery$ = new Rx.Subject();
const publicQuery$ = new Rx.Subject();
this.myQuery.onSnapshot((querySnapshot) => {
    myQuery$.next(querySnapshot.docs.map(d => d.data()  ));
});
this.publicQuery.onSnapshot((querySnapshot) => {
    publicQuery$.next(querySnapshot.docs.map(d => d.data()  ));
});
const orQuery$ = combineLatest(this.myQuery, …
Run Code Online (Sandbox Code Playgroud)

rxjs firebase google-cloud-firestore rxfire

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