Skip to content

Commit cd6dd0c

Browse files
authored
Improve example in README
1 parent c3126a4 commit cd6dd0c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,25 @@ The built-in presets only cover some use cases and are only able to check if val
204204
With the API you can use [JMESPath query syntax](http://jmespath.org) to define your own tests to check for additional properties and specific values. You can mix and match tests with presets.
205205

206206
```javascript
207-
const url = 'https://www.bbc.co.uk/news/world-us-canada-49060410'
207+
const testUrl = 'https://www.bbc.co.uk/news/world-us-canada-49060410'
208208

209209
const options = {
210210
tests: [
211211
// Check 'NewsArticle' schema exists in JSON-LD
212212
{ test: 'NewsArticle', expect: true, type: 'jsonld' },
213-
// Expect specific value for 'url' property, fail if value doesn't
214-
{ test: 'NewsArticle[*].url', expect: url },match
215-
// Warn but don't fail if test doesn't pass
216-
{ test: 'NewsArticle[*].mainEntityOfPage', expect: url, warning: true },
217-
// Test for twitter meta tag with specific value
213+
214+
// Check a 'NewsArticle' schema exists with 'url' property set to the value of the variable 'url'
215+
{ test: 'NewsArticle[*].url', expect: testUrl },
216+
217+
// A similar check as above, but won't fail (only warn) if the test doesn't pass
218+
{ test: 'NewsArticle[*].mainEntityOfPage', expect: testUrl, warning: true },
219+
220+
// Test for a Twitter meta tag with specific value
218221
{ test: '"twitter:domain"' expect: 'www.bbc.co.uk', type: 'metatag' }
219222
]
220223
}
221224

222-
structuredDataTest(url, options)
225+
structuredDataTest(testUrl, options)
223226
.then(response => { /**/ })
224227
.catch(err => { /**/ })
225228
```
@@ -228,7 +231,7 @@ structuredDataTest(url, options)
228231

229232
A preset is a collection of tests.
230233

231-
There are built-in presets you can use, you can list them with `--presets` option using the CLI. You can also easily define your own custom presets.
234+
There are built-in presets you can use, you can list them with `--presets` option using the CLI. You can also easily define your own custom presets when using the API. The Command Line Interface only supports built-in presets.
232235

233236
Presets must have a `name` (which should ideally be unique, but does not have to be) and `description` and an array of `test` objects in `tests`. Both `name` and `description` be arbitrary strings, `tests` should be an array of valid `test` objects.
234237

@@ -254,10 +257,10 @@ const MyCustomPreset = {
254257
{ test: '"twitter:card"', type: 'metatag' },
255258
{ test: '"twitter:domain"', expect: 'www.bbc.co.uk', type: 'metatag', }
256259
],
257-
// Other preset options:
260+
// Additional options you can use in a preset:
258261
// group: 'My Group Name', // A group name can be used to group tests in a preset (defaults to preset name)
259-
// schema: 'NewsArticle', // Specify a schema if all the tests in the preset apply to a specific schema
260-
// presets: [] // Any preset can also contain other presets
262+
// schema: 'NewsArticle', // Specify a schema at the top level if all the tests in the preset apply to the same schema
263+
// presets: [] // A preset can also invoke other presets, making it easy to re-use custom tests
261264
// conditional: {} // Define a conditional `test`, which is evaluated to determine if the preset should run
262265
}
263266

0 commit comments

Comments
 (0)