File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -621,6 +621,8 @@ class Dataset extends ServiceObject {
621621 /**
622622 * Create a Table object.
623623 *
624+ * @throws {TypeError } if table ID is missing.
625+ *
624626 * @param {string } id The ID of the table.
625627 * @param {object } [options] Table options.
626628 * @param {string } [options.location] The geographic location of the table, by
@@ -639,6 +641,10 @@ class Dataset extends ServiceObject {
639641 * const institutions = dataset.table('institution_data');
640642 */
641643 table ( id : string , options ?: TableOptions ) {
644+ if ( typeof id !== 'string' ) {
645+ throw new TypeError ( 'A table ID is required.' ) ;
646+ }
647+
642648 options = extend (
643649 {
644650 location : this . location ,
Original file line number Diff line number Diff line change @@ -1163,6 +1163,10 @@ export class BigQuery extends common.Service {
11631163 * const dataset = bigquery.dataset('higher_education');
11641164 */
11651165 dataset ( id : string , options ?: DataSetOptions ) {
1166+ if ( typeof id !== 'string' ) {
1167+ throw new TypeError ( 'A dataset ID is required.' ) ;
1168+ }
1169+
11661170 if ( this . location ) {
11671171 options = extend ( { location : this . location } , options ) ;
11681172 }
Original file line number Diff line number Diff line change @@ -785,6 +785,11 @@ describe('BigQuery/Dataset', () => {
785785 } ) ;
786786
787787 describe ( 'table' , ( ) => {
788+ it ( 'should throw an error if the id is missing' , ( ) => {
789+ const expectedErr = / A t a b l e I D i s r e q u i r e d \. / ;
790+ assert . throws ( ( ) => ds . table ( ) , expectedErr ) ;
791+ } ) ;
792+
788793 it ( 'should return a Table object' , ( ) => {
789794 const tableId = 'tableId' ;
790795 const table = ds . table ( tableId ) ;
Original file line number Diff line number Diff line change @@ -1248,6 +1248,11 @@ describe('BigQuery', () => {
12481248 describe ( 'dataset' , ( ) => {
12491249 const DATASET_ID = 'dataset-id' ;
12501250
1251+ it ( 'should throw an error if the id is missing' , ( ) => {
1252+ const expectedErr = / A d a t a s e t I D i s r e q u i r e d \. / ;
1253+ assert . throws ( ( ) => bq . dataset ( ) , expectedErr ) ;
1254+ } ) ;
1255+
12511256 it ( 'returns a Dataset instance' , ( ) => {
12521257 const ds = bq . dataset ( DATASET_ID ) ;
12531258 assert ( ds instanceof FakeDataset ) ;
You can’t perform that action at this time.
0 commit comments