File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
4
4
import { faCaretLeft } from '@fortawesome/free-solid-svg-icons/faCaretLeft' ;
5
5
import { faCaretRight } from '@fortawesome/free-solid-svg-icons/faCaretRight' ;
6
6
import $ from '~/helpers/$' ;
7
+ import { assertNotNull } from '~/helpers/data' ;
7
8
import { treatSpaceOrEnterAsClick } from '~/helpers/events' ;
8
9
9
10
function PseudoButton ( { onClick, children} : React . PropsWithChildren < {
@@ -49,7 +50,7 @@ export function Paginated({children, perPage=10}: {
49
50
}
50
51
useEffect ( ( ) => {
51
52
if ( pageChanged ) {
52
- $ . scrollTo ( ref . current as HTMLDivElement , 70 ) ;
53
+ $ . scrollTo ( assertNotNull ( ref . current ) , 70 ) ;
53
54
}
54
55
} , [ pageChanged ] ) ;
55
56
Original file line number Diff line number Diff line change @@ -7,6 +7,13 @@ export function assertDefined<T>(value: T | undefined): T {
7
7
return value ;
8
8
}
9
9
10
+ export function assertNotNull < T > ( value : T | null ) : T {
11
+ if ( value === null ) {
12
+ throw new Error ( 'Value is null' ) ;
13
+ }
14
+ return value ;
15
+ }
16
+
10
17
export function formatDateForBlog ( date : string ) {
11
18
if ( ! date ) {
12
19
return null ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { describe , test , expect } from '@jest/globals' ;
3
3
import { render , screen } from '@testing-library/preact' ;
4
- import { useSet , assertDefined } from '~/helpers/data' ;
4
+ import { useSet , assertDefined , assertNotNull } from '~/helpers/data' ;
5
5
6
6
function Component ( ) {
7
7
const s = useSet ( [ 1 ] ) ;
@@ -34,4 +34,9 @@ describe('helpers/data', () => {
34
34
35
35
expect ( ( ) => assertDefined ( foo ) ) . toThrowError ( ) ;
36
36
} ) ;
37
+ test ( 'assertNotNull throws' , ( ) => {
38
+ const foo = null ;
39
+
40
+ expect ( ( ) => assertNotNull ( foo ) ) . toThrowError ( ) ;
41
+ } ) ;
37
42
} ) ;
You can’t perform that action at this time.
0 commit comments