mirror of https://github.com/vuejs/vue.git
test: fix Object.prototype.watch related warnings
This commit is contained in:
parent
1f9e924971
commit
606666d5a9
|
|
@ -20,6 +20,7 @@ import {
|
||||||
hasOwn,
|
hasOwn,
|
||||||
isReserved,
|
isReserved,
|
||||||
handleError,
|
handleError,
|
||||||
|
nativeWatch,
|
||||||
validateProp,
|
validateProp,
|
||||||
isPlainObject,
|
isPlainObject,
|
||||||
isReservedAttribute
|
isReservedAttribute
|
||||||
|
|
@ -53,7 +54,9 @@ export function initState (vm: Component) {
|
||||||
observe(vm._data = {}, true /* asRootData */)
|
observe(vm._data = {}, true /* asRootData */)
|
||||||
}
|
}
|
||||||
if (opts.computed) initComputed(vm, opts.computed)
|
if (opts.computed) initComputed(vm, opts.computed)
|
||||||
if (opts.watch) initWatch(vm, opts.watch)
|
if (opts.watch && opts.watch !== nativeWatch) {
|
||||||
|
initWatch(vm, opts.watch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkOptionType (vm: Component, name: string) {
|
function checkOptionType (vm: Component, name: string) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ export const isAndroid = UA && UA.indexOf('android') > 0
|
||||||
export const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
|
export const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
|
||||||
export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
|
export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
|
||||||
|
|
||||||
|
// Firefix has a "watch" function on Object.prototype...
|
||||||
|
export const nativeWatch = ({}).watch
|
||||||
|
|
||||||
export let supportsPassive = false
|
export let supportsPassive = false
|
||||||
if (inBrowser) {
|
if (inBrowser) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
import { warn } from './debug'
|
import { warn } from './debug'
|
||||||
|
import { nativeWatch } from './env'
|
||||||
import { set } from '../observer/index'
|
import { set } from '../observer/index'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -172,6 +173,9 @@ ASSET_TYPES.forEach(function (type) {
|
||||||
* another, so we merge them as arrays.
|
* another, so we merge them as arrays.
|
||||||
*/
|
*/
|
||||||
strats.watch = function (parentVal: ?Object, childVal: ?Object): ?Object {
|
strats.watch = function (parentVal: ?Object, childVal: ?Object): ?Object {
|
||||||
|
// work around Firefox's Object.prototype.watch...
|
||||||
|
if (parentVal === nativeWatch) parentVal = undefined
|
||||||
|
if (childVal === nativeWatch) childVal = undefined
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!childVal) return Object.create(parentVal || null)
|
if (!childVal) return Object.create(parentVal || null)
|
||||||
if (!parentVal) return childVal
|
if (!parentVal) return childVal
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
|
||||||
export default function testObjectOption (name) {
|
export default function testObjectOption (name) {
|
||||||
it('should warn non object', () => {
|
it('should warn non object value', () => {
|
||||||
const options = {}
|
const options = {}
|
||||||
options[name] = () => {}
|
options[name] = () => {}
|
||||||
new Vue(options)
|
new Vue(options)
|
||||||
expect(`component option "${name}" should be an object`).toHaveBeenWarned()
|
expect(`component option "${name}" should be an object`).toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('don\'t warn when is an object', () => {
|
it('should not warn valid object value', () => {
|
||||||
const options = {}
|
const options = {}
|
||||||
options[name] = {}
|
options[name] = {}
|
||||||
new Vue(options)
|
new Vue(options)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ describe('Options watch', () => {
|
||||||
spy = jasmine.createSpy('watch')
|
spy = jasmine.createSpy('watch')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
testObjectOption('watch')
|
||||||
|
|
||||||
it('basic usage', done => {
|
it('basic usage', done => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -24,8 +26,6 @@ describe('Options watch', () => {
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
testObjectOption('watch')
|
|
||||||
|
|
||||||
it('string method name', done => {
|
it('string method name', done => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
data: {
|
data: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue