From bfeab1754e124e3e6f6ba78a945769445216f707 Mon Sep 17 00:00:00 2001 From: pimlie Date: Sat, 22 Jun 2019 16:50:23 +0200 Subject: [PATCH] fix: add warning for v1 boolean attribute syntax --- src/shared/merge.js | 6 +++++- test/unit/getMetaInfo.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/shared/merge.js b/src/shared/merge.js index b7b5349..8c184d5 100644 --- a/src/shared/merge.js +++ b/src/shared/merge.js @@ -1,7 +1,7 @@ import deepmerge from 'deepmerge' import { findIndex } from '../utils/array' import { applyTemplate } from './template' -import { metaInfoAttributeKeys } from './constants' +import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants' export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) { // we concat the arrays without merging objects contained in, @@ -80,6 +80,10 @@ export function merge(target, source, options = {}) { for (const key in source[attrKey]) { if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) { + if (booleanHtmlAttributes.includes(key)) { + // eslint-disable-next-line no-console + console.warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details') + } delete source[attrKey][key] } } diff --git a/test/unit/getMetaInfo.test.js b/test/unit/getMetaInfo.test.js index a7b631d..0e388c1 100644 --- a/test/unit/getMetaInfo.test.js +++ b/test/unit/getMetaInfo.test.js @@ -820,4 +820,36 @@ describe('getMetaInfo', () => { __dangerouslyDisableSanitizersByTagID: {} }) }) + + test.only('prints warning for boolean attributes with value undefined', () => { + const warn = jest.spyOn(console, 'warn').mockImplementation(() => {}) + + const component = new Vue({ + metaInfo: { + htmlAttrs: { + amp: undefined + } + } + }) + + expect(getMetaInfo(component)).toEqual({ + title: undefined, + titleChunk: '', + titleTemplate: '%s', + htmlAttrs: {}, + headAttrs: {}, + bodyAttrs: {}, + meta: [], + base: [], + link: [], + style: [], + script: [], + noscript: [], + __dangerouslyDisableSanitizers: [], + __dangerouslyDisableSanitizersByTagID: {} + }) + + expect(warn).toHaveBeenCalledTimes(1) + expect(warn).toHaveBeenCalledWith(expect.stringMatching('the value undefined')) + }) })