|
1 |
| -import { VNodeData, VNodeDirective } from "vue" |
2 |
| -import { mergeData } from "../src/index" |
| 1 | +import { VNodeData, VNodeDirective } from "vue"; |
| 2 | +import { mergeData } from "../src/index"; |
3 | 3 |
|
4 | 4 | it("should not mutate original object (issue #2)", () => {
|
5 |
| - let def1 = { on: { click() {} } } |
6 |
| - let def2 = { on: { click() {} } } |
| 5 | + let def1 = { on: { click() {} } }; |
| 6 | + let def2 = { on: { click() {} } }; |
7 | 7 |
|
8 |
| - let onclick1 = def1.on.click |
9 |
| - let onclick2 = def2.on.click |
| 8 | + let onclick1 = def1.on.click; |
| 9 | + let onclick2 = def2.on.click; |
10 | 10 |
|
11 |
| - let data = mergeData({}, def1, def2) |
| 11 | + let data = mergeData({}, def1, def2); |
12 | 12 |
|
13 |
| - expect(def1.on).not.toBe(data.on) |
14 |
| - expect(def2.on).not.toBe(data.on) |
| 13 | + expect(def1.on).not.toBe(data.on); |
| 14 | + expect(def2.on).not.toBe(data.on); |
15 | 15 |
|
16 |
| - expect(def1.on.click).toBe(onclick1) |
17 |
| - expect(def2.on.click).toBe(onclick2) |
| 16 | + expect(def1.on.click).toBe(onclick1); |
| 17 | + expect(def2.on.click).toBe(onclick2); |
18 | 18 |
|
19 |
| - expect(data.on.click).toContain(onclick1) |
20 |
| - expect(data.on.click).toContain(onclick2) |
21 |
| -}) |
| 19 | + expect(data.on.click).toContain(onclick1); |
| 20 | + expect(data.on.click).toContain(onclick2); |
| 21 | +}); |
22 | 22 |
|
23 | 23 | it("should set single handlers and concat multi", () => {
|
24 |
| - let h1 = console.log |
25 |
| - let h2 = console.info |
26 |
| - let h3 = console.error |
27 |
| - let actual: VNodeData |
| 24 | + let h1 = console.log; |
| 25 | + let h2 = console.info; |
| 26 | + let h3 = console.error; |
| 27 | + let actual: VNodeData; |
28 | 28 |
|
29 |
| - actual = mergeData({ class: ["btn", "text-center"] }, { on: { mouseup: h1 } }) |
30 |
| - expect(actual).toMatchObject({ on: { mouseup: h1 } }) |
31 |
| - expect(Array.isArray(actual.on.mouseup)).toBe(false) |
| 29 | + actual = mergeData( |
| 30 | + { class: ["btn", "text-center"] }, |
| 31 | + { on: { mouseup: h1 } } |
| 32 | + ); |
| 33 | + expect(actual).toMatchObject({ on: { mouseup: h1 } }); |
| 34 | + expect(Array.isArray(actual.on.mouseup)).toBe(false); |
32 | 35 |
|
33 |
| - actual = mergeData({ nativeOn: { mouseup: h1 } }, { class: ["btn", "text-center"] }) |
34 |
| - expect(actual).toMatchObject({ nativeOn: { mouseup: h1 } }) |
35 |
| - expect(Array.isArray(actual.nativeOn.mouseup)).toBe(false) |
| 36 | + actual = mergeData( |
| 37 | + { nativeOn: { mouseup: h1 } }, |
| 38 | + { class: ["btn", "text-center"] } |
| 39 | + ); |
| 40 | + expect(actual).toMatchObject({ nativeOn: { mouseup: h1 } }); |
| 41 | + expect(Array.isArray(actual.nativeOn.mouseup)).toBe(false); |
36 | 42 |
|
37 |
| - actual = mergeData({ on: { mouseup: h1 } }, { on: { mouseup: h2 } }, { on: { mouseup: h3 } }) |
38 |
| - expect(Array.isArray(actual.on.mouseup)).toBe(true) |
39 |
| - expect(actual.on.mouseup).toContain(h1) |
40 |
| - expect(actual.on.mouseup).toContain(h2) |
41 |
| - expect(actual.on.mouseup).toContain(h3) |
42 |
| -}) |
| 43 | + actual = mergeData( |
| 44 | + { on: { mouseup: h1 } }, |
| 45 | + { on: { mouseup: h2 } }, |
| 46 | + { on: { mouseup: h3 } } |
| 47 | + ); |
| 48 | + expect(Array.isArray(actual.on.mouseup)).toBe(true); |
| 49 | + expect(actual.on.mouseup).toContain(h1); |
| 50 | + expect(actual.on.mouseup).toContain(h2); |
| 51 | + expect(actual.on.mouseup).toContain(h3); |
| 52 | +}); |
43 | 53 |
|
44 | 54 | it("should call the right-most argument first", () => {
|
45 |
| - let first = 0 |
46 |
| - let factory = n => () => { |
47 |
| - if (!first) { |
48 |
| - first = n |
49 |
| - } |
50 |
| - } |
| 55 | + let first = 0; |
| 56 | + let factory = n => () => { |
| 57 | + if (!first) { |
| 58 | + first = n; |
| 59 | + } |
| 60 | + }; |
51 | 61 |
|
52 |
| - let actual = mergeData( |
53 |
| - { on: { click: factory(1) } }, |
54 |
| - { on: { click: factory(2) } }, |
55 |
| - { on: { click: factory(3) } }, |
56 |
| - { on: { click: factory(4) } } |
57 |
| - ) |
| 62 | + let actual = mergeData( |
| 63 | + { on: { click: factory(1) } }, |
| 64 | + { on: { click: factory(2) } }, |
| 65 | + { on: { click: factory(3) } }, |
| 66 | + { on: { click: factory(4) } } |
| 67 | + ); |
58 | 68 |
|
59 |
| - expect(Array.isArray(actual.on.click)).toBe(true) |
60 |
| - for (const fn of actual.on.click) { |
61 |
| - fn() |
62 |
| - } |
63 |
| - expect(first).toBe(4) |
64 |
| - expect(actual).toMatchSnapshot("merge-4") |
65 |
| -}) |
| 69 | + expect(Array.isArray(actual.on.click)).toBe(true); |
| 70 | + for (const fn of actual.on.click) { |
| 71 | + fn(); |
| 72 | + } |
| 73 | + expect(first).toBe(4); |
| 74 | + expect(actual).toMatchSnapshot("merge-4"); |
| 75 | +}); |
0 commit comments