Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlucas/gasmask
Mocks for Google Apps Script libraries, specifically around Spreadsheets
https://github.com/vlucas/gasmask
google google-apps-script hacktoberfest mocks testing testing-tools
Last synced: about 1 month ago
JSON representation
Mocks for Google Apps Script libraries, specifically around Spreadsheets
- Host: GitHub
- URL: https://github.com/vlucas/gasmask
- Owner: vlucas
- Created: 2020-12-20T00:58:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-18T19:23:58.000Z (7 months ago)
- Last Synced: 2024-12-06T00:09:20.804Z (about 2 months ago)
- Topics: google, google-apps-script, hacktoberfest, mocks, testing, testing-tools
- Language: TypeScript
- Homepage:
- Size: 371 KB
- Stars: 23
- Watchers: 6
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GASMask
Mocks and stubs/dummies for Google Apps Script (GAS).
## Why?
Google Apps Script add-ons (like [BudgetSheet](https://www.budgetsheet.net) - the add-on I am developing) make a of
calls to globally available APIs that Google provides to your scripts. Unfortunately, Google does not provide any
standard mocking library for these APIs, so individual library authors are left to mock those global libraries
themselves in order to make their code unit testable.## Focus
For now, the focus of this library is around **SpreadsheetApp** since that is the specific Google add-on I am
delevoping. The eventual goal is to cover most or all of the Google Apps Script APIs with full type support, with
community support.## Installation
To use `gasmask` install it in your project as a devDependency:
```
npm i gasmask -D
```Now you are ready to get started using gasmask in your tests.
## Usage
Assuming you are trying to test a method that shows a simple toast message:
```javascript
function showToastMessage(msg, title) {
const ss = SpreadsheetApp.getActiveSpreadsheet();ss.toast(msg, title || 'My Add-On');
},
```Just import what you need to use in your tests:
```javascript
import { Spreadsheet } from 'gasmask';describe('showToastMessage', () => {
it('should display a toast message to the user', () => {
const testMessage = 'test message here';
const mockToast = jest.spyOn(Spreadsheet, 'toast'); // Spy the 'Spreadsheet.toast' method to ensure it gets called// Call our method
showToastMessage(testMessage);// Now we ensure that it was called with the correct arguments
expect(mockToast).toBeCalledWith(testMessage, 'My Add-On');
});
});
```