File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11export { default as isCreated } from './is-created' ;
22export { default as isOk } from './is-ok' ;
33export { default as findHttpStatus } from './find-http-status' ;
4+ export { default as validateHttpStatus } from './validate-http-status' ;
Original file line number Diff line number Diff line change 1+ function validateHttpStatus ( status , expectedStatus ) {
2+ try {
3+ const isValid = status === expectedStatus ;
4+
5+ if ( ! isValid ) {
6+ throw new Error ( `Expected a ${ expectedStatus } response.` ) ;
7+ }
8+ return isValid ;
9+ } catch ( e ) {
10+ return e ;
11+ }
12+ }
13+
14+ export default validateHttpStatus ;
Original file line number Diff line number Diff line change 1+ import { validateHttpStatus } from '../src' ;
2+
3+ const STATUS_EXPECTED = 200 ;
4+
5+ describe ( 'validateHttpStatus' , ( ) => {
6+ test ( 'it should validate http status 200' , ( ) => {
7+ const received = validateHttpStatus ( 200 , STATUS_EXPECTED ) ;
8+ expect ( received ) . toBeTruthy ( ) ;
9+ } ) ;
10+
11+ test ( 'it should throw Error when wrong status be passed' , ( ) => {
12+ const received = validateHttpStatus ( 400 , STATUS_EXPECTED ) ;
13+ expect ( received . message ) . toBe ( 'Expected a 200 response.' ) ;
14+ } ) ;
15+ } ) ;
You can’t perform that action at this time.
0 commit comments