@@ -49,15 +49,15 @@ fn load_more() -> impl Future<Item = JsValue, Error = JsValue> {
49
49
50
50
fn document ( ) -> web_sys:: Document {
51
51
web_sys:: window ( )
52
- . expect ( "no window" )
52
+ . expect_throw ( "no window" )
53
53
. document ( )
54
- . expect ( "no document" )
54
+ . expect_throw ( "no document" )
55
55
}
56
56
57
57
fn add_load_more_button ( ) {
58
58
let btn = document ( )
59
59
. create_element ( "button" )
60
- . expect ( "could not create button" ) ;
60
+ . expect_throw ( "could not create button" ) ;
61
61
btn. set_inner_html ( "I WANT MORE PUPPIES" ) ;
62
62
let on_click = Closure :: wrap (
63
63
Box :: new ( move || future_to_promise ( load_more ( ) ) ) as Box < FnMut ( ) -> js_sys:: Promise >
@@ -67,12 +67,13 @@ fn add_load_more_button() {
67
67
& on_click
68
68
. as_ref ( )
69
69
. dyn_ref ( )
70
- . expect ( "on click is not a Function" ) ,
70
+ . expect_throw ( "on click is not a Function" ) ,
71
71
)
72
- . expect ( "could not add event listener to load more button" ) ;
72
+ . expect_throw ( "could not add event listener to load more button" ) ;
73
73
74
- let doc = document ( ) . body ( ) . expect ( "no body" ) ;
75
- doc. append_child ( & btn) . expect ( "could not append button" ) ;
74
+ let doc = document ( ) . body ( ) . expect_throw ( "no body" ) ;
75
+ doc. append_child ( & btn)
76
+ . expect_throw ( "could not append button" ) ;
76
77
77
78
on_click. forget ( ) ;
78
79
}
@@ -82,27 +83,27 @@ fn render_response(response: graphql_client_web::Response<puppy_smiles::Response
82
83
83
84
log ( & format ! ( "response body\n \n {:?}" , response) ) ;
84
85
85
- let parent = document ( ) . body ( ) . expect ( "no body" ) ;
86
+ let parent = document ( ) . body ( ) . expect_throw ( "no body" ) ;
86
87
87
88
let json: graphql_client_web:: Response < puppy_smiles:: ResponseData > = response;
88
89
let response = document ( )
89
90
. create_element ( "div" )
90
- . expect ( "could not create div" ) ;
91
+ . expect_throw ( "could not create div" ) ;
91
92
let mut inner_html = String :: new ( ) ;
92
93
let listings = json
93
94
. data
94
- . expect ( "response data" )
95
+ . expect_throw ( "response data" )
95
96
. reddit
96
- . expect ( "reddit" )
97
+ . expect_throw ( "reddit" )
97
98
. subreddit
98
- . expect ( "puppy smiles subreddit" )
99
+ . expect_throw ( "puppy smiles subreddit" )
99
100
. new_listings ;
100
101
101
102
let new_cursor: Option < String > = listings[ listings. len ( ) - 1 ]
102
103
. as_ref ( )
103
104
. map ( |puppy| puppy. fullname_id . clone ( ) )
104
105
. to_owned ( ) ;
105
- LAST_ENTRY . lock ( ) . unwrap ( ) . replace ( new_cursor) ;
106
+ LAST_ENTRY . lock ( ) . unwrap_throw ( ) . replace ( new_cursor) ;
106
107
107
108
for puppy in & listings {
108
109
if let Some ( puppy) = puppy {
@@ -118,7 +119,7 @@ fn render_response(response: graphql_client_web::Response<puppy_smiles::Response
118
119
"# ,
119
120
puppy. title, puppy. url, puppy. title
120
121
)
121
- . expect ( "write to string" ) ;
122
+ . expect_throw ( "write to string" ) ;
122
123
}
123
124
}
124
125
response. set_inner_html ( & format ! (
@@ -127,20 +128,20 @@ fn render_response(response: graphql_client_web::Response<puppy_smiles::Response
127
128
) ) ;
128
129
parent
129
130
. append_child ( & response)
130
- . expect ( "could not append response" ) ;
131
+ . expect_throw ( "could not append response" ) ;
131
132
}
132
133
133
134
#[ wasm_bindgen( start) ]
134
135
pub fn run ( ) {
135
136
log ( "Hello there" ) ;
136
137
let message_area = document ( )
137
138
. create_element ( "div" )
138
- . expect ( "could not create div" ) ;
139
+ . expect_throw ( "could not create div" ) ;
139
140
message_area. set_inner_html ( "<p>good morning</p>" ) ;
140
- let parent = document ( ) . body ( ) . unwrap ( ) ;
141
+ let parent = document ( ) . body ( ) . unwrap_throw ( ) ;
141
142
parent
142
143
. append_child ( & message_area)
143
- . expect ( "could not append message area" ) ;
144
+ . expect_throw ( "could not append message area" ) ;
144
145
145
146
load_more ( ) ;
146
147
add_load_more_button ( ) ;
0 commit comments