{"id":19381005,"url":"https://github.com/holidaycheck/redux-pre-thunk","last_synced_at":"2026-05-06T14:41:25.837Z","repository":{"id":57351312,"uuid":"89052397","full_name":"holidaycheck/redux-pre-thunk","owner":"holidaycheck","description":"Pre thunk middleware for unit testing","archived":false,"fork":false,"pushed_at":"2017-10-24T14:34:43.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-08T09:41:06.196Z","etag":null,"topics":["javascript","react","redux","redux-thunk","testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/holidaycheck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-22T07:28:33.000Z","updated_at":"2018-07-19T21:22:11.000Z","dependencies_parsed_at":"2022-08-31T06:20:13.184Z","dependency_job_id":null,"html_url":"https://github.com/holidaycheck/redux-pre-thunk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holidaycheck%2Fredux-pre-thunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holidaycheck%2Fredux-pre-thunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holidaycheck%2Fredux-pre-thunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holidaycheck%2Fredux-pre-thunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/holidaycheck","download_url":"https://codeload.github.com/holidaycheck/redux-pre-thunk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240517246,"owners_count":19814163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","react","redux","redux-thunk","testing"],"created_at":"2024-11-10T09:15:34.779Z","updated_at":"2026-05-06T14:41:20.814Z","avatar_url":"https://github.com/holidaycheck.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Redux Pre-Thunk middleware\n===\n\nDispatch arrays before using [redux-thunk](https://github.com/gaearon/redux-thunk) and make your code testable again!\n\nBut why?\n===\n\nLet's say we have the following action:\n\n```javascript\nfunction myThunkAction(firstArgument, secondArgument){\n    return function(dispatch, getState){\n        // call some backend service with arguments\n    }\n}\n```\n\nand usage in some component:\n\n```javascript\ndispatch(myThunkAction(firstArgument, secondArgument));\n```\n\n`myThunkAction` can be tested on your own, however if you try to test the place where it is used, you have either to repeat mocking the backend service as it was done in it's unit test or write a poor test which won't check it's parameters.\n\nThe test would look like this:\n```javascript\nexpect(dispatch).to.have.been.calledOnce; // not so informative, what if we change arguments and it fails?\n```\n\nYou can't check the argument value as invoked thunk returns anonymous function. Passing wrong arguments will cause an error. You can even switch entire function as long as test only tells that something was dispatched. Not so good.\n\nIs there way to avoid this test gap?\n===\n\nYes!\n===\n\nUsing the following structure will allow us to check the arguments:\n\n\n```javascript\ndispatch([ myThunkAction, firstArgument, secondArgument ]);\n```\n\nWith test: \n```javascript\nexpect(dispatch).to.have.been.calledWith([ myThunkAction, firstArgument, secondArgument ])\n```\n\nThis tells us clearly that all arguments are right in place. We are safe and ready to move forward without worries.\n\nSetup\n===\n\n\n```javascript\nimport preThunk from 'redux-pre-thunk';\n```\n\nAdd middleware before thunk one. Now the following action will be handled:\n\n```javascript\n\n// first argument is action creator followed by arguments which will be used\ndispatch([ myThunkAction, firstArgument, secondArgument ]);\n```\n\n\nContributions\n---\n\nIf you have some more ideas you're welcome to create the PR and discuss things together.\n\nHave a nice day!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholidaycheck%2Fredux-pre-thunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholidaycheck%2Fredux-pre-thunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholidaycheck%2Fredux-pre-thunk/lists"}