1.0.8 • Published 6 years ago
gas-mock-service v1.0.8
Gas Mock Service
This library is dedicated to mock the google apps script services
It accumulates data which can be useful for writing tests and debugging the codebase.
Installation
npm install --save-dev gas-mock-service
Usage
import { Card } from 'gas-mock-service'
or in Common.js
const Card = require('gas-mock-service')
Test example (Jest)
import { Card } from 'gas-mock-service'
import GenericView from 'src/views/Generic'
import data from '../helpers/mocks/responses/getData.json'
describe('Generic View', () => {
it('Runs the render method and checks the returned data is a card instance', () => {
const card = new GenericView({ data }).render()
expect(card).toBeInstanceOf(Card)
expect(card.printJson()).toMatchSnapshot()
})
})
As you can see using mock services is super easy and straightforward. All you have to do is import the specific class to your test file.
In our expample we use mock API response to use that data in GenericView
constructor call.
Also, we check if the JSON representation of the view corresponds the snapshot.
Contribution
Running tests
npm test
Publish
npm version
npm publish --access public
NOTE that to contribute you should make sure that:
- you've covered your code with tests
- all the tests pass if you run
npm test
- you added your newe added class/service to readme and follow the highlighting pattern
Useful links
Script services
CardService
Classes^1:Action
ActionResponse
ActionResponseBuilder
AuthorizationAction
AuthorizationException
Button
ButtonSet
Card
CardAction
CardBuilder
CardHeader
CardSection
ComposeActionResponse
ComposeActionResponseBuilder
Image
ImageButton
KeyValue
setAuthorizationAction(action)
setBottomLabel(text)
setButton(button)
setComposeAction(action, composedEmailType)
setContent(text)
setIcon(icon)
setIconAltText(altText)
setMultiline(multiline)
setOnClickAction(action)
setOnClickOpenLinkAction(action)
setOpenLink(openLink)
setSwitch(switchToSet)
setTopLabel(text)
Navigation
Notification
OpenLink
SectionInput
Suggestions
SuggestionsResponse
SuggestionsResponseBuilder
Switch
TextButton
TextInput
TextParagraph
UniversalActionResponse
UniversalActionResponseBuilder
Widget
Enums:ComposedEmailType
Icon
ImageStyle
LoadIndicator
NotificationType
OnClose
OpenAs
SelectionInputType
PropertiesService
Classes:CacheService
Classes:Classes:
^1: All the CardService
classes and their methods which are currently mocked in this library are marked as bold