|
1 |
| -import { deepCopy } from '../../src/util' |
| 1 | +import { find, deepCopy, forEachValue, isObject, isPromise, assert } from '../../src/util' |
2 | 2 |
|
3 | 3 | describe('util', () => {
|
| 4 | + it('find', () => { |
| 5 | + const list = [33, 22, 112, 222, 43] |
| 6 | + expect(find(list, function (a) { return a % 2 === 0 })).toEqual(22) |
| 7 | + }) |
| 8 | + |
4 | 9 | it('deepCopy: nornal structure', () => {
|
5 | 10 | const original = {
|
6 | 11 | a: 1,
|
@@ -38,4 +43,40 @@ describe('util', () => {
|
38 | 43 |
|
39 | 44 | expect(copy).toEqual(original)
|
40 | 45 | })
|
| 46 | + |
| 47 | + it('forEachValue', () => { |
| 48 | + let number = 1 |
| 49 | + |
| 50 | + function plus (value, key) { |
| 51 | + number += value |
| 52 | + } |
| 53 | + const origin = { |
| 54 | + a: 1, |
| 55 | + b: 3 |
| 56 | + } |
| 57 | + |
| 58 | + forEachValue(origin, plus) |
| 59 | + expect(number).toEqual(5) |
| 60 | + }) |
| 61 | + |
| 62 | + it('isObject', () => { |
| 63 | + expect(isObject(1)).toBe(false) |
| 64 | + expect(isObject('String')).toBe(false) |
| 65 | + expect(isObject(undefined)).toBe(false) |
| 66 | + expect(isObject({})).toBe(true) |
| 67 | + expect(isObject(null)).toBe(false) |
| 68 | + expect(isObject([])).toBe(true) |
| 69 | + expect(isObject(new Function())).toBe(false) |
| 70 | + }) |
| 71 | + |
| 72 | + it('isPromise', () => { |
| 73 | + const promise = new Promise(() => {}, () => {}) |
| 74 | + expect(isPromise(1)).toBe(false) |
| 75 | + expect(isPromise(promise)).toBe(true) |
| 76 | + expect(isPromise(new Function())).toBe(false) |
| 77 | + }) |
| 78 | + |
| 79 | + it('assert', () => { |
| 80 | + expect(assert.bind(null, false, 'Hello')).toThrowError('[vuex] Hello') |
| 81 | + }) |
41 | 82 | })
|
0 commit comments