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
With the spec file foundation, the custom element can now be created and applied to the mock DOM environment. To do this, we use the Web Test Runner (WTR) framework which provides the scaffolding to test Web Componets in a browser environment.
211
205
212
-
The WTR and the full setup is covered in greater detail within [the GreenwoodJS test runner docs](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/). In an attempt to not duplicate those docs, an outline has been provided here, but please refer to those docs for a full user guide.
206
+
The WTR and the full setup is covered in greater detail within [the GreenwoodJS test runner docs](https://www.greenwood.dev/guides/ecosystem/web-test-runner/). In an attempt to not duplicate those docs, an outline has been provided here, but please refer to those docs for a full user guide.
Install dependencies and configure WTR. This project has that covered already! ✅ (Let's chat if there becomes a need to reconfigure the current setup.)
If using a Greenwood resource plugin, you'll need to provide that info to stub out the signiture.
229
223
230
-
1. **[Mock Data Requests](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/#content-as-data)**
224
+
1. **[Mock Data Requests](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#content-as-data)**
231
225
232
226
If using Greenwood's Content as Data feature, mocking `fetch` with mock data is necessary.
233
227
@@ -285,6 +279,38 @@ components/
285
279
my-component.stories.js
286
280
```
287
281
282
+
#### _Content as Data_ Stories
283
+
284
+
When a component requires a `fetch` request for data, the story will need to mock this request before being able to render within the Storybook.
285
+
286
+
To mock `fetch`, create a `parameter` within the story export object named `fetchMock`. This object contains a `mocks` array with a `matcher` for the localhost network request URL. The `matcher.response` object represents the mocked data to use with the story.
287
+
288
+
Checkout [the `blog-posts-list.stories.js` story](https://github.com/ProjectEvergreen/www.greenwoodjs.dev/blob/main/src/components/blog-posts-list/blog-posts-list.stories.js) as an example.
289
+
290
+
```js
291
+
import"./my-custom-element.js";
292
+
importpagesfrom"../../stories/mocks/graph.json";
293
+
294
+
exportdefault {
295
+
title:"Components/My Custom Element",
296
+
parameters: {
297
+
// ...other parameters, if necessary...
298
+
fetchMock: {
299
+
mocks: [
300
+
{
301
+
matcher: {
302
+
url:"http://localhost:1985/graph.json",
303
+
response: {
304
+
body: pages,
305
+
},
306
+
},
307
+
},
308
+
],
309
+
},
310
+
},
311
+
};
312
+
```
313
+
288
314
## Hosting and Deployment
289
315
290
316
This project is hosted on Netlify and automatically deploys on each merge into main. Release branches will be curated over the course of a Greenwood release cycle and then merged at the time the new Greenwood release is published to NPM.
0 commit comments