|
@@ -1,6 +1,11 @@
|
|
|
-import { deepCopy } from '../../src/util'
|
|
|
+import { find, deepCopy, forEachValue, isObject, isPromise, assert } from '../../src/util'
|
|
|
|
|
|
describe('util', () => {
|
|
|
+ it('find', () => {
|
|
|
+ const list = [33, 22, 112, 222, 43]
|
|
|
+ expect(find(list, function (a) { return a % 2 === 0 })).toEqual(22)
|
|
|
+ })
|
|
|
+
|
|
|
it('deepCopy: nornal structure', () => {
|
|
|
const original = {
|
|
|
a: 1,
|
|
@@ -38,4 +43,40 @@ describe('util', () => {
|
|
|
|
|
|
expect(copy).toEqual(original)
|
|
|
})
|
|
|
+
|
|
|
+ it('forEachValue', () => {
|
|
|
+ let number = 1
|
|
|
+
|
|
|
+ function plus (value, key) {
|
|
|
+ number += value
|
|
|
+ }
|
|
|
+ const origin = {
|
|
|
+ a: 1,
|
|
|
+ b: 3
|
|
|
+ }
|
|
|
+
|
|
|
+ forEachValue(origin, plus)
|
|
|
+ expect(number).toEqual(5)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('isObject', () => {
|
|
|
+ expect(isObject(1)).toBe(false)
|
|
|
+ expect(isObject('String')).toBe(false)
|
|
|
+ expect(isObject(undefined)).toBe(false)
|
|
|
+ expect(isObject({})).toBe(true)
|
|
|
+ expect(isObject(null)).toBe(false)
|
|
|
+ expect(isObject([])).toBe(true)
|
|
|
+ expect(isObject(new Function())).toBe(false)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('isPromise', () => {
|
|
|
+ const promise = new Promise(() => {}, () => {})
|
|
|
+ expect(isPromise(1)).toBe(false)
|
|
|
+ expect(isPromise(promise)).toBe(true)
|
|
|
+ expect(isPromise(new Function())).toBe(false)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('assert', () => {
|
|
|
+ expect(assert.bind(null, false, 'Hello')).toThrowError('[vuex] Hello')
|
|
|
+ })
|
|
|
})
|