Skip to content

Commit

Permalink
fix sheetcount, make row props enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim committed Feb 5, 2020
1 parent 561c6eb commit bd8eba6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/GoogleSpreadsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class GoogleSpreadsheet {
// WORKSHEETS ////////////////////////////////////////////////////////////////////////////////////
get sheetCount() {
this._ensureInfoLoaded();
return this._rawSheets.length;
return _.values(this._rawSheets).length;
}

get sheetsById() {
Expand Down
1 change: 1 addition & 0 deletions lib/GoogleSpreadsheetRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GoogleSpreadsheetRow {
Object.defineProperty(this, propName, {
get: () => this._rawData[i],
set: (newVal) => { this._rawData[i] = newVal; },
enumerable: true,
});
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Theo Ephraim <[email protected]> (https://theoephraim.com)",
"name": "google-spreadsheet",
"description": "Google Sheets API (v4) -- simple interface to read/write data and manage sheets",
"version": "3.0.3",
"version": "3.0.4",
"license": "Unlicense",
"keywords": [
"google spreadsheets",
Expand Down
2 changes: 2 additions & 0 deletions test/manage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('Managing doc info and sheets', () => {
});

it('can add a sheet', async () => {
const numSheets = doc.sheetCount;
sheet = await doc.addWorksheet({
title: newSheetTitle,
gridProperties: {
Expand All @@ -71,6 +72,7 @@ describe('Managing doc info and sheets', () => {
},
headers: ['col1', 'col2', 'col3', 'col4', 'col5'],
});
expect(doc.sheetCount).toBe(numSheets + 1);

expect(sheet.title).toBe(newSheetTitle);
});
Expand Down
8 changes: 4 additions & 4 deletions test/rows.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ describe('Row-based operations', () => {
it('allows empty headers', async () => {
await sheet.setHeaderRow(['', 'col1', '', 'col2']);
rows = await sheet.getRows();
expect(rows[0]['']).toBeUndefined();
expect(rows[0].col1).not.toBeUndefined();
expect(rows[0]).not.toHaveProperty('');
expect(rows[0]).toHaveProperty('col1');
});

it('trims each header', async () => {
await sheet.setHeaderRow([' col1 ', ' something with spaces ']);
rows = await sheet.getRows();
expect(rows[0].col1).not.toBeUndefined();
expect(rows[0]['something with spaces']).not.toBeUndefined();
expect(rows[0]).toHaveProperty('col1');
expect(rows[0]).toHaveProperty(['something with spaces']);
});

it('throws an error if setting duplicate headers', async () => {
Expand Down

0 comments on commit bd8eba6

Please sign in to comment.