Skip to content

Commit 0801c8c

Browse files
committed
test: helper function
1 parent 5071213 commit 0801c8c

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

packages/nuejs/test/test-fors/fors.test.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,83 @@
11
import { mkConfigBase, mountTestComponent } from '../test-utils.js'
22

33
const mkConfig = mkConfigBase(import.meta.url)
4+
const arr = (parent) => Array.from(parent.querySelectorAll('li')).map(e => e.textContent)
5+
46

57
describe('Nue.js Fors Tests', () => {
68
test('Array', async () => {
79
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array'))
810

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'])
1112

1213
cleanup()
1314
})
1415

1516
test('Unpacking Array', async () => {
1617
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-unpack'))
1718

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'])
2020

2121
cleanup()
2222
})
2323

2424
test('Numbered Array', async () => {
2525
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-numbered'))
2626

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'])
2928

3029
cleanup()
3130
})
3231

3332
test('Object Array', async () => {
3433
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-object-array'))
3534

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'])
3836

3937
cleanup()
4038
})
4139

4240
test('Array replaced', async () => {
4341
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-replace'))
4442

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'])
4844
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'])
5246

5347
cleanup()
5448
})
5549

5650
test('Array funcs', async () => {
5751
const { app, cleanup } = await mountTestComponent(mkConfig('test-for-array-funcs'))
58-
const arr = () => Array.from(app.$el.querySelectorAll('li')).map(e => e.textContent)
5952

60-
expect(arr()).toEqual(['hello', 'world'])
53+
expect(arr(app.$el)).toEqual(['hello', 'world'])
6154

6255
app.$refs.push.click()
6356
app.$refs.push.click()
64-
expect(arr()).toEqual(['hello', 'world', '42', '42'])
57+
expect(arr(app.$el)).toEqual(['hello', 'world', '42', '42'])
6558

6659
app.$refs.pop.click()
67-
expect(arr()).toEqual(['hello', 'world', '42'])
60+
expect(arr(app.$el)).toEqual(['hello', 'world', '42'])
6861

6962
app.$refs.unshift.click()
7063
app.$refs.unshift.click()
71-
expect(arr()).toEqual(['answer', 'answer', 'hello', 'world', '42'])
64+
expect(arr(app.$el)).toEqual(['answer', 'answer', 'hello', 'world', '42'])
7265

7366
app.$refs.shift.click()
74-
expect(arr()).toEqual(['answer', 'hello', 'world', '42'])
67+
expect(arr(app.$el)).toEqual(['answer', 'hello', 'world', '42'])
7568

7669
app.$refs.reverse.click()
77-
expect(arr()).toEqual(['42', 'world', 'hello', 'answer'])
70+
expect(arr(app.$el)).toEqual(['42', 'world', 'hello', 'answer'])
7871

7972
app.$refs.remove.click()
80-
expect(arr()).toEqual(['42', 'world', 'answer'])
73+
expect(arr(app.$el)).toEqual(['42', 'world', 'answer'])
8174

8275
app.$refs.splice.click()
83-
expect(arr()).toEqual(['42', 'answer'])
76+
expect(arr(app.$el)).toEqual(['42', 'answer'])
8477

8578
app.$refs.push.click() // additional 42 at end for sort
8679
app.$refs.sort.click()
87-
expect(arr()).toEqual(['42', '42', 'answer'])
80+
expect(arr(app.$el)).toEqual(['42', '42', 'answer'])
8881

8982
cleanup()
9083
})

0 commit comments

Comments
 (0)