Answer a question

I am trying to project state and props into the selector. When console logging inside the selector running the test, the variables exist and work as expected. But my expect line throws errors saying expected undefined to equal ...

    fit('should return the data based on ID passed in', () => {
        const props = {
            id: '67891'
        }
        const state = {
            data: [
                { id: '12345', startDate: '2018-01-01', endDate: '2019-01-01' },
                { id: '67891', startDate: '2018-01-01', endDate: '2019-01-01' },
                { id: '14567', startDate: '2018-01-01', endDate: '2019-01-01' }
            ]
        };
        const result = state.data[1]

        expect(selectors.getDataByID.projector(state, props)).toEqual(jasmine.objectContaining(result));
    });
export const getDataByID = createSelector(
    getState,
    (state, props) => {
        const data = Object.values(state.data);
        data.find((element: any) => props.id === element.id)
    }
  );

I'm not sure what's going on, as reading through the docs on the NGRX site seems to support what I am doing here, so does previous examples across the web. The variable data is available in the selector, but in the test it says undefined?

Any help appreciated, fairly new to NGRX. Thanks.

Answers

Try returning something, the rest seems fine.

return data.find((element: any) => props.id === element.id)
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐