소스 검색

fix Object.prototype.watch test case

Evan You 9 년 전
부모
커밋
7b069453ed
1개의 변경된 파일16개의 추가작업 그리고 18개의 파일을 삭제
  1. 16 18
      test/unit/features/options/extends.spec.js

+ 16 - 18
test/unit/features/options/extends.spec.js

@@ -46,28 +46,22 @@ describe('Options extends', () => {
     expect(vm.b).toBe(2)
     expect(vm.c).toBe(3)
   })
-})
 
-describe('Options extends with Object.prototype.watch', () => {
-  beforeAll(function () {
+  it('should work with global mixins + Object.prototype.watch', done => {
+    let fakeWatch = false
     if (!Object.prototype.watch) {
+      fakeWatch = true
       // eslint-disable-next-line no-extend-native
-      Object.prototype.watch = {
-        remove: true
-      }
-    }
-  })
-  afterAll(function () {
-    if (Object.prototype.watch && Object.prototype.watch.remove) {
-      delete Object.prototype.watch
+      Object.defineProperty(Object.prototype, 'watch', {
+        writable: true,
+        configurable: true,
+        enumerable: false,
+        value: () => {}
+      })
     }
-  })
-  it('should work with global mixins', done => {
-    Vue.use({
-      install: function () {
-        Vue.mixin({})
-      }
-    })
+
+    Vue.mixin({})
+
     const spy = jasmine.createSpy('watch')
     const A = Vue.extend({
       data: function () {
@@ -85,6 +79,10 @@ describe('Options extends with Object.prototype.watch', () => {
     })
     waitForUpdate(() => {
       expect(spy).toHaveBeenCalledWith(2, 1)
+
+      if (fakeWatch) {
+        delete Object.prototype.watch
+      }
     }).then(done)
   })
 })