File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -268,14 +268,14 @@ function load(path) {
268268}
269269
270270function getStatusFromDefinition ( nockDef ) {
271- // Backward compatibility for when `status` was encoded as string in `reply`.
271+ // Backward compatibility for when `status` was encoded as string in `reply`.
272272 if ( ! _ . isUndefined ( nockDef . reply ) ) {
273- // Try parsing `reply` property.
274273 const parsedReply = parseInt ( nockDef . reply , 10 )
275- if ( _ . isNumber ( parsedReply ) ) {
276- return parsedReply
274+ if ( isNaN ( parsedReply ) ) {
275+ throw Error ( '`reply`, when present, must be a numeric string' )
277276 }
278- // TODO-coverage: `else` throw with an error.
277+
278+ return parsedReply
279279 }
280280
281281 const DEFAULT_STATUS_OK = 200
Original file line number Diff line number Diff line change @@ -50,6 +50,24 @@ test('define() is backward compatible', t => {
5050 req . end ( )
5151} )
5252
53+ test ( 'define() throws when reply is not a numeric string' , t => {
54+ t . throws (
55+ ( ) =>
56+ nock . define ( [
57+ {
58+ scope : 'http://example.com:1451' ,
59+ method : 'GET' ,
60+ path : '/' ,
61+ reply : 'frodo' ,
62+ } ,
63+ ] ) ,
64+ {
65+ message : '`reply`, when present, must be a numeric string' ,
66+ }
67+ )
68+ t . end ( )
69+ } )
70+
5371test ( 'define() applies default status code when none is specified' , async t => {
5472 const body = '�'
5573
You can’t perform that action at this time.
0 commit comments