-
Notifications
You must be signed in to change notification settings - Fork 193
refactor: use props check instead of version check #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable no-eval */ | ||
import React from 'react'; | ||
import { getNodeRef } from '../src/ref'; | ||
|
||
jest.mock('react', () => { | ||
const react19 = jest.requireActual('react-19'); | ||
return react19; | ||
}); | ||
|
||
jest.mock('react-dom', () => { | ||
const reactDom19 = jest.requireActual('react-dom-19'); | ||
return reactDom19; | ||
}); | ||
|
||
describe('ref: React 19', () => { | ||
const errSpy = jest.spyOn(console, 'error'); | ||
|
||
beforeEach(() => { | ||
errSpy.mockReset(); | ||
}); | ||
|
||
it('getNodeRef', () => { | ||
const ref = React.createRef<HTMLDivElement>(); | ||
const node = <div ref={ref} />; | ||
|
||
expect(getNodeRef(node)).toBe(ref); | ||
|
||
expect(errSpy).not.toHaveBeenCalled(); | ||
}); | ||
Comment on lines
+22
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议增加更多测试用例 当前测试只覆盖了基本场景,建议添加以下测试用例:
示例测试用例: it('should handle null/undefined', () => {
expect(getNodeRef(null)).toBe(null);
expect(getNodeRef(undefined)).toBe(null);
});
it('should handle non-React elements', () => {
expect(getNodeRef('string')).toBe(null);
expect(getNodeRef(123)).toBe(null);
});
it('should work with function ref', () => {
const fnRef = jest.fn();
const node = <div ref={fnRef} />;
expect(getNodeRef(node)).toBe(fnRef);
}); |
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议优化 ref 获取逻辑的实现
当前实现存在以下问题:
propertyIsEnumerable
方法可能不安全null
分支缺少测试覆盖建议进行如下优化:
📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 90-90: Do not access Object.prototype method 'propertyIsEnumerable' from target object.
(lint/suspicious/noPrototypeBuiltins)
🪛 GitHub Check: codecov/patch
[warning] 92-92: src/ref.ts#L92
Added line #L92 was not covered by tests