Closed akshikrm closed 2 weeks ago
The changes in the ToastItem
component involve an update to the PropTypes declaration, specifically altering the id
property within the toast
object from a required number to a required string. This adjustment indicates that the id
is now expected to be a string type. The component's overall functionality, including state management and rendering, remains intact, continuing to manage visibility and handle toast removal.
File | Change Summary |
---|---|
frontend/src/components/Toast/ToastItem.jsx | Updated id PropType from number.isRequired to string.isRequired |
frontend/src/tests/components/Toast/ToastItem.test.jsx | Modified mockToast to use dynamic id generation and updated properties for testing |
Objective | Addressed | Explanation |
---|---|---|
Change toast.id PropType to avoid warnings (#315) |
✅ |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
This change will get rid of the warning but not fix the issue. We need to find out where this originates. We use the same lines of code to generate a toast notification, so that behavior is unexpected
I found out that in the Toast Component line number:13, the id is generated as a string and not a number as mentioned in the prop-types, this is where the issue is coming from.
useEffect(() => {
....
> id: `${Date.now()}-${Math.random()}`,
....
}, []);
and if you take a look at ToastItem.test.jsx line:7 the id is a number, hence the test is passing without throwing any error.
describe('ToastItem', () => {
....
> const mockToast = { id: 1, message: 'Test Toast', duration: 1000 };
...
With the above findings the generated in the Toast component can be converted into a number type and it should fix the source of the issue.
I have made the changes changes, could you take a look at them
Now I get this in tests:
stderr | src/tests/components/Toast/ToastItem.test.jsx > ToastItem > renders toast message correctly
Warning: Failed prop type: Invalid prop `toast.id` of type `number` supplied to `ToastItem`, expected `string`.
at ToastItem (C:\Users\Eren\Documents\bluewave-onboarding\frontend\src\components\Toast\ToastItem.jsx:13:22)
Where do we supply type number?
Any updates?
Fixed the invalid prop issue. Issue was because of in ToastItem.PropTypes id was of the type number but the generated toast.id is a string.
closes #315