Comments (6)
Hey @Arturszott, what the benefit of this implementation?
from reapop.
When I'm testing redux actions I can now check if dispatch was called with the object, which was not available when we were dealing with thunk. function instance !== function instance.
Plain objects are iteratable so I can write:
dispatch(createNotification({ status: 'error', title: 'Errrrrr', message: 'something went wrong' }));
expect(dispatch).to.have.been.calledWith({
type: '__SEND_NOTIFICATION__',
payload: { status: 'error', title: 'Errrrrr', message: 'something went wrong' }
})
from reapop.
I don't understand the benefit of this test, since we already test each action creators ?
from reapop.
Sure. Action creators are tested by itself, but I want to make sure in my action file, that I'm passing the right set of data to it. I can't do this when actionCreator is returning a thunk, because parameters are held inside within the closure.
from reapop.
I'm sorry man but I still don't understand why do you want to check its parameter since we test each actions creators by checking the result in the store. Eg (source) :
it('should create an action to add a notification ' +
'(add `id` property and convert status)', () => {
notification.id = null;
// we remove the image, otherwise `treatNotification()` helper will update
// status of notification
notification.image = null;
// here we simulate an HTTP success status code (200 = OK)
notification.status = 200;
const notificationAdded = store.dispatch(addNotification(notification));
const expectedAction = [{
type: types.ADD_NOTIFICATION,
payload: Object.assign({}, notification, {
id: notificationAdded.id,
status: SUCCESS_STATUS
})
}];
expect(store.getActions()).toEqual(expectedAction);
});
that's why these tests are enough to be sure that if we add a notification { status: 'error', title: 'Errrrrr', message: 'something went wrong' }
with addNotification
(async action creator), the store will contains an action {type: 'ADD_NOTIFICATION', payload: { id:1231231234, status: 'error', title: 'Errrrrr', message: 'something went wrong' }
.
from reapop.
Hmm. Okay, now I get your way of thinking.
For me this kind of test is introducing too much boilerplate into the testing code. That was the reason why I decided to create this middleware. I like my test with the least configuration possible. For testing with store is has to be set first and configured.
Thanks for reviewing my idea anyway. I wanted to share the idea of the code, that actually works for me, but what works for me must not necessary work for you!
from reapop.
Related Issues (20)
- TypeError: Cannot read property 'filter' of undefined HOT 1
- How do I properly implement onClick for buttons? Noticed button onClick fires when notification is triggered. HOT 2
- Theme - notificationButtons style is not passed to the buttons container
- Undefined payload HOT 7
- Attaching Notification OnClick events to the specific notification HOT 3
- Wrong default class for NotificationIcon HOT 1
- [email protected] doesn't have "dist" folder in it HOT 3
- Mutation detected HOT 4
- Specify Message Tag HOT 2
- Cut a new release on npm HOT 7
- Failed to execute 'animate' on 'Element': Partial keyframes are not supported HOT 4
- IE11 not support HOT 3
- Hydration Mismatch in Next.js v13 HOT 3
- Is sending a notification in one component supposed to rerender parallel components? HOT 3
- `ReactNode` vs `string` for message HOT 4
- Close notification programatically HOT 7
- Promise support for notifications HOT 2
- Problem with useNotifications() while testing HOT 2
- FYI, https://louisbarranqueiro.github.io/reapop/ displays as a blank page as of 2023-10-07 HOT 1
- Theme and Transition not working in demo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reapop.