Closed Zrce closed 4 years ago
Sorry, that looks like a bug in the documentation! Thank you for reporting it.
The line:
const { ReportageNewsArticle, Twitter, Facebook } = require('./presets')
Should read:
const {
ReportageNewsArticle,
Twitter,
Facebook
} = require('structured-data-testing-tool/presets')
I've updated README, the update to it will go out in the next release.
Thanks. Actually I still get
TypeError: Cannot read property 'name' of undefined
Oh no! Sorry, I looked closer and the example is completely wrong (it is outdated).
Please try this, and let me know if you have any questions:
const { structuredDataTest } = require('structured-data-testing-tool')
const { Google, Twitter, Facebook } = require('structured-data-testing-tool/presets')
const url = 'https://www.bbc.co.uk/news/world-us-canada-49060410'
let result
structuredDataTest(url, {
// Check for compliance with Google, Twitter and Facebook recommendations
presets: [ Google, Twitter, Facebook ],
// Check the page includes a specific Schema (see https://schema.org/docs/full.html for a list)
schemas: [ 'ReportageNewsArticle' ]
})
.then(res => {
result = res
console.log('✅ All tests passed!')
})
.catch(err => {
if (err.type === 'VALIDATION_FAILED') {
result = err.res
console.log('❌ Some tests failed.')
if (result.failed.length > 0) console.log("⚠️ Errors:\n", result.failed.map(test => test))
}
} else {
console.log(err) // Handle other errors here (e.g. an error fetching a URL)
}
})
.finally(() => {
if (result) {
console.log(
`Passed: ${result.passed.length},`,
`Failed: ${result.failed.length},`,
`Warnings: ${result.warnings.length}`,
)
console.log(`Schemas found: ${result.schemas.join(',')}`)
})
I'll fix this in the documentation and improve the error handling so the error messages are better if anyone else runs into this issue.
Thanks to your feedback, a version with updated documentation has been released!
I've also added this and one other example to the examples directory.
Feel free to re-open this issue (or open a new one) if you run into any more problems.
Im failing with
if I try this code in the documentation.