You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,47 @@ const result = await runAirtableScript({
118
118
119
119
You can pass one of `us`, `friendly`, `european`, or `iso`.
120
120
121
+
### Mocking fetch requests
122
+
123
+
Airtable scripts can either use `fetch`, or in extensions `remoteFetchAsync` to make HTTP requests. You can mock these requests using the `fetchMock` setting:
124
+
125
+
```js
126
+
constresult=awaitrunAirtableScript({
127
+
script: myScript,
128
+
base: baseFixture,
129
+
fetchMock: (url, request) => {
130
+
return {
131
+
status:200,
132
+
body:JSON.stringify({ message:'Hello, world!' }),
133
+
}
134
+
},
135
+
})
136
+
```
137
+
138
+
### Mocking user inputs
139
+
140
+
You can mock any `input` from either an automation input or user interaction using the `mockInput` setting:
141
+
142
+
```js
143
+
constresults=awaitrunAirtableScript({
144
+
script:`
145
+
const text = await input.textAsync('Select a table')
146
+
output.inspect(text)
147
+
`,
148
+
base: randomRecords,
149
+
mockInput: {
150
+
// @ts-ignore
151
+
textAsync: (label) => {
152
+
if (label ==='Select a table') {
153
+
return'text123'
154
+
}
155
+
},
156
+
},
157
+
})
158
+
```
159
+
160
+
Every [input method for extensions or automations](https://airtable.com/developers/scripting/api/input) are available to be mocked. Check out the [input.test.ts](./test/input.test.ts) file for examples.
161
+
121
162
### Results
122
163
123
164
The results from calling `runAirtableScript` are an object with several properties:
0 commit comments