Skip to content

Commit 526e2bc

Browse files
committed
Issue-110: Update with PR feedback
1 parent 44dbd77 commit 526e2bc

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

CONTRIBUTING.md

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ The following is an example of a spec file, with imports, a global mock (`fetch`
192192
import { expect } from "@esm-bundle/chai";
193193
import "./my-custom-element.js";
194194
195-
window.fetch = function () {
196-
return new Promise((resolve) => {
197-
resolve(new Response(JSON.stringify({ foo: "mock response" })));
198-
});
199-
};
200-
201195
describe("Components/My Custom Element", () => {
202196
it("should do something expected", () => {
203197
expect("something").equal("some" + "thing");
@@ -209,25 +203,25 @@ describe("Components/My Custom Element", () => {
209203
210204
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.
211205
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.
213207
214-
1. **[Setup](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/#setup)**
208+
1. **[Setup](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#setup)**
215209
216210
Install dependencies and configure WTR. This project has that covered already! ✅ (Let's chat if there becomes a need to reconfigure the current setup.)
217211
218-
1. **[Usage](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/#usage)**
212+
1. **[Usage](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#usage)**
219213
220214
Within a traditional `before` block, create the custom element, and append to the DOM. See the example below. 👇
221215
222-
1. **[Static Assets](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/#static-assets)**
216+
1. **[Static Assets](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#static-assets)**
223217
224218
If experiencing a 404 for a missing asset, a simple middleware can help mock that request. Otherwise, you can skip this section.
225219
226-
1. **[Install Resource Plugins](https://super-tapioca-5987ce.netlify.app/guides/ecosystem/web-test-runner/#resource-plugins)**
220+
1. **[Install Resource Plugins](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#resource-plugins)**
227221
228222
If using a Greenwood resource plugin, you'll need to provide that info to stub out the signiture.
229223
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)**
231225
232226
If using Greenwood's Content as Data feature, mocking `fetch` with mock data is necessary.
233227
@@ -285,6 +279,38 @@ components/
285279
my-component.stories.js
286280
```
287281
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+
import pages from "../../stories/mocks/graph.json";
293+
294+
export default {
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+
288314
## Hosting and Deployment
289315
290316
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

Comments
 (0)