File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ class Replicate {
3333 * @param {Function } [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
3434 */
3535 constructor ( options ) {
36+ if ( ! options . auth ) {
37+ throw new Error ( 'Missing required parameter: auth' ) ;
38+ }
39+
3640 this . auth = options . auth ;
3741 this . userAgent =
3842 options . userAgent || `replicate-javascript/${ packageJSON . version } ` ;
Original file line number Diff line number Diff line change @@ -33,6 +33,22 @@ describe('Replicate client', () => {
3333 } ) ;
3434 expect ( clientWithCustomUserAgent . userAgent ) . toBe ( 'my-app/1.2.3' ) ;
3535 } ) ;
36+
37+ test ( 'Throws error if no auth token is provided' , ( ) => {
38+ const expected = 'Missing required parameter: auth'
39+
40+ expect ( ( ) => {
41+ new Replicate ( { auth : undefined } ) ;
42+ } ) . toThrow ( expected ) ;
43+
44+ expect ( ( ) => {
45+ new Replicate ( { auth : null } ) ;
46+ } ) . toThrow ( expected ) ;
47+
48+ expect ( ( ) => {
49+ new Replicate ( { auth : "" } ) ;
50+ } ) . toThrow ( expected ) ;
51+ } ) ;
3652 } ) ;
3753
3854 describe ( 'collections.list' , ( ) => {
You can’t perform that action at this time.
0 commit comments