-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dom: Add types progressively to dom modules (#30103)
* dom: Add types progressively to dom modules * Add tests to assertIsDefined * Try fix e2e * Move defined assertion
- Loading branch information
1 parent
c63361b
commit 4b8b2d9
Showing
7 changed files
with
57 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
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,25 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
|
||
describe( 'assertIsDefined', () => { | ||
it( 'should throw if the variable is null', () => { | ||
expect( () => assertIsDefined( null, 'val' ) ).toThrow( | ||
"Expected 'val' to be defined, but received null" | ||
); | ||
} ); | ||
|
||
it( 'should throw if the variable is undefined', () => { | ||
expect( () => assertIsDefined( undefined, 'val' ) ).toThrow( | ||
"Expected 'val' to be defined, but received undefined" | ||
); | ||
} ); | ||
|
||
it.each( [ 0, '', NaN, -0, 1, new String(), {}, [], false, Infinity ] )( | ||
'should not throw if the value is %s', | ||
( val ) => { | ||
expect( () => assertIsDefined( val, 'val' ) ).not.toThrow(); | ||
} | ||
); | ||
} ); |
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,10 @@ | ||
export function assertIsDefined< T >( | ||
val: T, | ||
name: string | ||
): asserts val is NonNullable< T > { | ||
if ( val === undefined || val === null ) { | ||
throw new Error( | ||
`Expected '${ name }' to be defined, but received ${ val }` | ||
); | ||
} | ||
} |
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