]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: fix observer warning case
authorEvan You <yyx990803@gmail.com>
Mon, 1 Oct 2018 22:40:44 +0000 (18:40 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 1 Oct 2018 22:40:44 +0000 (18:40 -0400)
packages/observer/__tests__/observable.spec.ts

index d50d2ca3231b91cbc7caf8558685712c3ea86dd8..bdf4a75a83dd5b68ca29148b905a1def482b193f 100644 (file)
@@ -124,20 +124,36 @@ describe('observer/observable', () => {
   })
 
   test('unobservable values', () => {
-    const msg = 'not observable'
+    const warn = jest.spyOn(console, 'warn')
+    let lastMsg: string
+    warn.mockImplementation(msg => {
+      lastMsg = msg
+    })
+
+    const getMsg = (value: any) => `value is not observable: ${String(value)}`
+    const assertValue = (value: any) => {
+      observable(value)
+      expect(lastMsg).toMatch(getMsg(value))
+    }
+
     // number
-    expect(() => observable(1)).toThrowError(msg)
+    assertValue(1)
     // string
-    expect(() => observable('foo')).toThrowError(msg)
+    assertValue('foo')
     // boolean
-    expect(() => observable(false)).toThrowError(msg)
+    assertValue(false)
     // null
-    expect(() => observable(null)).toThrowError(msg)
+    assertValue(null)
     // undefined should work because it returns empty object observable
-    expect(() => observable(undefined)).not.toThrowError(msg)
+    lastMsg = ''
+    observable(undefined)
+    expect(lastMsg).toBe('')
     // symbol
     const s = Symbol()
-    expect(() => observable(s)).toThrowError(msg)
+    assertValue(s)
+
+    warn.mockRestore()
+
     // built-ins should work and return same value
     const p = Promise.resolve()
     expect(observable(p)).toBe(p)