I have an action called addItemsToCollection
which triggers a call to an API like so:
import {CALL_API} from 'redux-api-middleware';
export function addItemsToCollection(collectionId, itemIds)
{
return {[CALL_API]:
{
endpoint: `/collections/${collectionId}/items`,
method: 'POST',
body: JSON.stringify(itemIds),
types:
[
ADD_ITEMS,
{ type: ADD_ITEMS_SUCCESS },
ADD_ITEMS_FAIL
]
}
};
}
When I try to write a test simply for this action being created such as:
it('should create an action to add items to a collection', () =>
{
const collectionId = 1;
const itemIds = [1,2,3];
const expectedAction =
{
[CALL_API]:
{
endpoint: `/collections/${collectionId}/items`,
method: 'POST',
body: JSON.stringify(itemIds),
types:
[
ADD_ITEMS,
{ type: ADD_ITEMS_SUCCESS },
ADD_ITEMS_FAIL
]
}
};
expect(addItemsToCollection(collectionId, itemIds)).toEqual(expectedAction);
});
It does pass but that is because it is returning and empty object {} for expectedAction as well as from the action creator function. Not much use.
So my questions are,
Why are empty objects being returned?
What is the proper way to make this test?
Aucun commentaire:
Enregistrer un commentaire