Reputation: 469
Hello I'm trying to test the createSelector
function in jest
but I'm stuck. So the problem is that never enters in the if
of the function getContent
and I need to enter, for the coverage.
File
export const selectDetailsObject = createSelector(
[
(state) => state.objectId,
(state) => state.objects,
],
(
objectId,
objects,
) => getContent(objectId, objects)
)
function getContent (objectId, objects) {
const result = {}
if (objectId && objectId !== '') {
result.objectId = objectId
result.objectInfo = objects[objectId]
result.objectDetails = objectDetails[objectId]
}
return result
}
Testing file
const mockStore = () => ({
objectId: '123',
objects: {},
})
test('should select the content of the table', () => {
const result = selectDetailsObject(mockStore)
expect(result.objects).toBe()
})
Any suggestions?
Upvotes: 2
Views: 4628
Reputation: 9887
selectDetailsObject
needs a state object, not a function. So you can either just create a mockStore object, or call it when you hand it in:
const mockStore = () => ({
objectId: '123',
objects: {},
})
test('should select the content of the table', () => {
const result = selectDetailsObject(mockStore())
expect(result.objects).toBe()
})
Upvotes: 2