-
-
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.
* backport #3968 * backport #3964 * backport #3997 * backport #3995 * backport #3970 * backport #3971 * backport #3990 * backport #3963 * backport #3962 * backport #3960 * backport #3956 * Revert "backport #3963" This reverts commit 86a372a. * define public type * fix newline issue
- Loading branch information
1 parent
4601cf3
commit f0144e6
Showing
23 changed files
with
274 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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,74 @@ | ||
import { createElement, render, createRef } from 'preact'; | ||
import { | ||
useState, | ||
useEffect, | ||
useLayoutEffect, | ||
useCallback, | ||
useMemo, | ||
useImperativeHandle | ||
} from 'preact/hooks'; | ||
import { setupRerender } from 'preact/test-utils'; | ||
import { setupScratch, teardown } from '../../../test/_util/helpers'; | ||
import 'preact/debug'; | ||
|
||
/** @jsx createElement */ | ||
|
||
describe('Hook argument validation', () => { | ||
/** | ||
* @param {string} name | ||
* @param {(arg: number) => void} hook | ||
*/ | ||
function validateHook(name, hook) { | ||
const TestComponent = ({ initialValue }) => { | ||
const [value, setValue] = useState(initialValue); | ||
hook(value); | ||
|
||
return ( | ||
<button type="button" onClick={() => setValue(NaN)}> | ||
Set to NaN | ||
</button> | ||
); | ||
}; | ||
|
||
it(`should error if ${name} is mounted with NaN as an argument`, async () => { | ||
expect(() => | ||
render(<TestComponent initialValue={NaN} />, scratch) | ||
).to.throw(/Hooks should not be called with NaN in the dependency array/); | ||
}); | ||
|
||
it(`should error if ${name} is updated with NaN as an argument`, async () => { | ||
render(<TestComponent initialValue={0} />, scratch); | ||
|
||
expect(() => { | ||
scratch.querySelector('button').click(); | ||
rerender(); | ||
}).to.throw( | ||
/Hooks should not be called with NaN in the dependency array/ | ||
); | ||
}); | ||
} | ||
|
||
/** @type {HTMLElement} */ | ||
let scratch; | ||
/** @type {() => void} */ | ||
let rerender; | ||
|
||
beforeEach(() => { | ||
scratch = setupScratch(); | ||
rerender = setupRerender(); | ||
}); | ||
|
||
afterEach(() => { | ||
teardown(scratch); | ||
}); | ||
|
||
validateHook('useEffect', arg => useEffect(() => {}, [arg])); | ||
validateHook('useLayoutEffect', arg => useLayoutEffect(() => {}, [arg])); | ||
validateHook('useCallback', arg => useCallback(() => {}, [arg])); | ||
validateHook('useMemo', arg => useMemo(() => {}, [arg])); | ||
|
||
const ref = createRef(); | ||
validateHook('useImperativeHandle', arg => { | ||
useImperativeHandle(ref, () => undefined, [arg]); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.