
Research
Security News
Malicious npm Packages Use Telegram to Exfiltrate BullX Credentials
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
redux-ledger
Advanced tools
Tiny redux middleware to run integration tests with thunks!
npm install --save-dev redux-ledger
Add ledger
middleware to your Redux store. Simulate events and dispatch
just as you would before. It will intercept and record all actions. Once you
are ready, use ledger.resolve()
to wait for any pending
thunks to complete, then run your assertions.
Note - For accurate results place ledger
as the first middleware in the store.
Every action in the store can be recorded by adding the middleware to the store.
import makeLedger from "redux-ledger";
import { createStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
const doA = payload => ({ type: "action_a", payload });
const doB = payload => ({ type: "action_b", payload });
// For the purposes of a demo these are defined inline ...
const doAsyncA = payload => dispatch => {
return Promise.resolve().then(() => {
dispatch(doA(payload));
});
};
// ... but let's pretend they are some long running requests, mocked or not
const doAsyncB = payload => dispatch => {
return Promise.resolve().then(() => {
dispatch(doB(payload));
});
};
test("asynchronous actions fired from my App", () => {
const ledger = makeLedger();
const store = createStore(
(state = {}) => state,
applyMiddleware(ledger, thunk)
);
store.dispatch(doA({ foo: "foo" }));
store.dispatch(doB({ bar: "bar" }));
// ledger.getActions() to get all actions recorded
expect(ledger.getActions()).toMatchSnapshot();
});
redux-ledger
shines when you want to unit test an entire component connected to
a store.
import makeLedger from "redux-ledger";
import { createStore, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import { mount } from "enzyme";
// Component to test
import MyAppContainer from "my-app-container";
test("asynchronous actions fired from my App", () => {
const ledger = makeLedger();
const store = createStore(reducer, applyMiddleware(ledger, thunk));
const wrapper = mount(
<Provider store={store}>
<MyAppContainer />
</Provider>
);
// Simulate user interaction which will kick off asynchronous actions
wrapper.find(MyAppContainer).simulate("click");
return ledger.resolve().then(actions => {
expect(actions).toMatchSnapshot();
});
});
createLedger()
- FactoryYou'll want a new ledger for each new store, as ledgers should
be scoped to a single store. Returns a ledger
middleware instance.
ledger
- InstanceThe middleware function. Has additional methods on the function object:
// Will wait for any pending promise from actions to finish.
// Resolves with the array of actions dispatched
ledger.resolve().then(actions => { ... });
// Will return all actions recorded so far
ledger.getActions(); // [ { type: 'a', ...}, {type: 'b', ...} ]
// Will clear any previously recorded actions
ledger.clearActions();
FAQs
Redux unit test middleware
The npm package redux-ledger receives a total of 2 weekly downloads. As such, redux-ledger popularity was classified as not popular.
We found that redux-ledger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.
Security News
AI-generated slop reports are making bug bounty triage harder, wasting maintainer time, and straining trust in vulnerability disclosure programs.