throw on unexpected keys in expectBadge() (#7354)

* throw on unexpected object keys

* fix docs.rs tests

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
chris48s
2021-12-10 21:26:41 +00:00
committed by GitHub
parent 380a6e3b9f
commit 015c39336b
2 changed files with 23 additions and 8 deletions

View File

@@ -49,14 +49,29 @@ const factory = superclass =>
return this
}
expectBadge({ label, message, logoWidth, labelColor, color, link }) {
expectBadge(badge) {
const expectedKeys = [
'label',
'message',
'logoWidth',
'labelColor',
'color',
'link',
]
for (const key of Object.keys(badge)) {
if (!expectedKeys.includes(key)) {
throw new Error(`Found unexpected object key '${key}'`)
}
}
return this.afterJSON(json => {
this.constructor._expectField(json, 'label', label)
this.constructor._expectField(json, 'message', message)
this.constructor._expectField(json, 'logoWidth', logoWidth)
this.constructor._expectField(json, 'labelColor', labelColor)
this.constructor._expectField(json, 'color', color)
this.constructor._expectField(json, 'link', link)
this.constructor._expectField(json, 'label', badge.label)
this.constructor._expectField(json, 'message', badge.message)
this.constructor._expectField(json, 'logoWidth', badge.logoWidth)
this.constructor._expectField(json, 'labelColor', badge.labelColor)
this.constructor._expectField(json, 'color', badge.color)
this.constructor._expectField(json, 'link', badge.link)
})
}