|
1 | 1 | import { mkConfigBase, mountTestComponent } from '../test-utils.js'
|
2 | 2 |
|
3 | 3 | const mkConfig = mkConfigBase(import.meta.url)
|
| 4 | +const arr = (parent) => Array.from(parent.querySelectorAll('li')).map(e => e.textContent) |
| 5 | + |
4 | 6 |
|
5 | 7 | describe('Nue.js Fors Tests', () => {
|
6 | 8 | test('Array', async () => {
|
7 | 9 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array'))
|
8 | 10 |
|
9 |
| - const list = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
10 |
| - expect(list).toEqual(['hello', 'world', '42']) |
| 11 | + expect(arr(app.$el)).toEqual(['hello', 'world', '42']) |
11 | 12 |
|
12 | 13 | cleanup()
|
13 | 14 | })
|
14 | 15 |
|
15 | 16 | test('Unpacking Array', async () => {
|
16 | 17 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-unpack'))
|
17 | 18 |
|
18 |
| - const list = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
19 |
| - expect(list).toEqual(['hello', '42']) |
| 19 | + expect(arr(app.$el)).toEqual(['hello', '42']) |
20 | 20 |
|
21 | 21 | cleanup()
|
22 | 22 | })
|
23 | 23 |
|
24 | 24 | test('Numbered Array', async () => {
|
25 | 25 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-numbered'))
|
26 | 26 |
|
27 |
| - const list = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
28 |
| - expect(list).toEqual(['0: hello', '1: world', '2: 42']) |
| 27 | + expect(arr(app.$el)).toEqual(['0: hello', '1: world', '2: 42']) |
29 | 28 |
|
30 | 29 | cleanup()
|
31 | 30 | })
|
32 | 31 |
|
33 | 32 | test('Object Array', async () => {
|
34 | 33 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-object-array'))
|
35 | 34 |
|
36 |
| - const list = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
37 |
| - expect(list).toEqual(['hello', 'world', '42']) |
| 35 | + expect(arr(app.$el)).toEqual(['hello', 'world', '42']) |
38 | 36 |
|
39 | 37 | cleanup()
|
40 | 38 | })
|
41 | 39 |
|
42 | 40 | test('Array replaced', async () => {
|
43 | 41 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-replace'))
|
44 | 42 |
|
45 |
| - const listA = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
46 |
| - expect(listA).toEqual(['hello']) |
47 |
| - |
| 43 | + expect(arr(app.$el)).toEqual(['hello']) |
48 | 44 | app.$el.querySelector('button').click()
|
49 |
| - |
50 |
| - const listB = Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
51 |
| - expect(listB).toEqual(['world']) |
| 45 | + expect(arr(app.$el)).toEqual(['world']) |
52 | 46 |
|
53 | 47 | cleanup()
|
54 | 48 | })
|
55 | 49 |
|
56 | 50 | test('Array funcs', async () => {
|
57 | 51 | const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-funcs'))
|
58 |
| - const arr = () => Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent) |
59 | 52 |
|
60 |
| - expect(arr()).toEqual(['hello', 'world']) |
| 53 | + expect(arr(app.$el)).toEqual(['hello', 'world']) |
61 | 54 |
|
62 | 55 | app.$refs.push.click()
|
63 | 56 | app.$refs.push.click()
|
64 |
| - expect(arr()).toEqual(['hello', 'world', '42', '42']) |
| 57 | + expect(arr(app.$el)).toEqual(['hello', 'world', '42', '42']) |
65 | 58 |
|
66 | 59 | app.$refs.pop.click()
|
67 |
| - expect(arr()).toEqual(['hello', 'world', '42']) |
| 60 | + expect(arr(app.$el)).toEqual(['hello', 'world', '42']) |
68 | 61 |
|
69 | 62 | app.$refs.unshift.click()
|
70 | 63 | app.$refs.unshift.click()
|
71 |
| - expect(arr()).toEqual(['answer', 'answer', 'hello', 'world', '42']) |
| 64 | + expect(arr(app.$el)).toEqual(['answer', 'answer', 'hello', 'world', '42']) |
72 | 65 |
|
73 | 66 | app.$refs.shift.click()
|
74 |
| - expect(arr()).toEqual(['answer', 'hello', 'world', '42']) |
| 67 | + expect(arr(app.$el)).toEqual(['answer', 'hello', 'world', '42']) |
75 | 68 |
|
76 | 69 | app.$refs.reverse.click()
|
77 |
| - expect(arr()).toEqual(['42', 'world', 'hello', 'answer']) |
| 70 | + expect(arr(app.$el)).toEqual(['42', 'world', 'hello', 'answer']) |
78 | 71 |
|
79 | 72 | app.$refs.remove.click()
|
80 |
| - expect(arr()).toEqual(['42', 'world', 'answer']) |
| 73 | + expect(arr(app.$el)).toEqual(['42', 'world', 'answer']) |
81 | 74 |
|
82 | 75 | app.$refs.splice.click()
|
83 |
| - expect(arr()).toEqual(['42', 'answer']) |
| 76 | + expect(arr(app.$el)).toEqual(['42', 'answer']) |
84 | 77 |
|
85 | 78 | app.$refs.push.click() // additional 42 at end for sort
|
86 | 79 | app.$refs.sort.click()
|
87 |
| - expect(arr()).toEqual(['42', '42', 'answer']) |
| 80 | + expect(arr(app.$el)).toEqual(['42', '42', 'answer']) |
88 | 81 |
|
89 | 82 | cleanup()
|
90 | 83 | })
|
|
0 commit comments