-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4302 from ziongh/main
feat: added isMemo to compact to allow compatibility with react-is dependant libraries
- Loading branch information
Showing
3 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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,37 @@ | ||
import { createElement as preactCreateElement, Fragment } from 'preact'; | ||
import React, { createElement, isMemo, memo } from 'preact/compat'; | ||
|
||
describe('isMemo', () => { | ||
it('should check return false for invalid arguments', () => { | ||
expect(isMemo(null)).to.equal(false); | ||
expect(isMemo(false)).to.equal(false); | ||
expect(isMemo(true)).to.equal(false); | ||
expect(isMemo('foo')).to.equal(false); | ||
expect(isMemo(123)).to.equal(false); | ||
expect(isMemo([])).to.equal(false); | ||
expect(isMemo({})).to.equal(false); | ||
}); | ||
|
||
it('should detect a preact memo', () => { | ||
function Foo() { | ||
return <h1>Hello World</h1>; | ||
} | ||
let App = memo(Foo); | ||
expect(isMemo(App)).to.equal(true); | ||
}); | ||
|
||
it('should not detect a normal element', () => { | ||
function Foo() { | ||
return <h1>Hello World</h1>; | ||
} | ||
expect(isMemo(Foo)).to.equal(false); | ||
}); | ||
|
||
it('should detect a preact vnode as false', () => { | ||
expect(isMemo(preactCreateElement(Fragment, {}))).to.equal(false); | ||
}); | ||
|
||
it('should detect a compat vnode as false', () => { | ||
expect(isMemo(React.createElement(Fragment, {}))).to.equal(false); | ||
}); | ||
}); |