Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit bf00671

Browse files
committed
test: simplify button.test.js
1 parent b365207 commit bf00671

File tree

1 file changed

+101
-97
lines changed

1 file changed

+101
-97
lines changed

tests/components/button/button.test.js

Lines changed: 101 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -25,155 +25,159 @@ describe('tests button', () => {
2525
})
2626

2727
it('should the component has two tags', () => {
28-
expect(Object.keys(docButton['tags']).length).toEqual(2)
29-
})
30-
31-
it('should give the component a size prop with default value to "normal"', () => {
32-
expect(docButton['props']['size']['defaultValue']['value']).toEqual('"normal"')
33-
})
34-
35-
it('should the component has size prop description equal The size of the button', () => {
36-
expect(docButton['props']['size']['description']).toEqual('The size of the button')
37-
})
38-
39-
it('should the component has color prop description equal The color for the button example', () => {
40-
expect(docButton['props']['color']['description']).toEqual('The color for the button example')
41-
})
42-
43-
it('should the component has color prop default equal #333', () => {
44-
expect(docButton['props']['color']['defaultValue']['value']).toEqual('"#333"')
28+
expect(Object.keys(docButton.tags).length).toEqual(2)
4529
})
4630

4731
it('should the component has authors', () => {
48-
expect(typeof docButton['tags']['author'] !== 'undefined').toBe(true)
32+
expect(docButton.tags.author).not.toBeUndefined()
4933
})
5034

5135
it('should not see the method without tag @public', () => {
52-
expect(docButton['methods'].length).toEqual(0)
36+
expect(docButton.methods.length).toEqual(0)
5337
})
5438

5539
it('should have props', () => {
56-
expect(typeof docButton['props'] !== 'undefined').toBe(true)
40+
expect(docButton.props).not.toBeUndefined()
5741
})
5842

5943
it('should the component has version', () => {
60-
expect(typeof docButton['tags']['version'] !== 'undefined').toBe(true)
61-
})
44+
expect(docButton.tags.version).not.toBeUndefined()
45+
})
46+
describe('props', () => {
47+
let props
48+
49+
beforeAll(() => {
50+
props = docButton.props ? docButton.props : {}
51+
})
52+
it('should give the component a size prop with default value to "normal"', () => {
53+
expect(props.size.defaultValue).toMatchObject({ value: '"normal"' })
54+
})
55+
56+
it('should the component has size prop description equal The size of the button', () => {
57+
expect(props.size.description).toEqual('The size of the button')
58+
})
6259

63-
it('should the component has fourteen props', () => {
64-
expect(Object.keys(docButton['props']).length).toEqual(14)
65-
})
60+
it('should the component has color prop description equal The color for the button example', () => {
61+
expect(props.color.description).toEqual('The color for the button example')
62+
})
6663

67-
it('should the component has propsAnother prop default equal \'blue\'', () => {
68-
expect(docButton['props']['propsAnother']['defaultValue']['value']).toEqual('"blue"')
69-
})
64+
it('should the component has color prop default equal #333', () => {
65+
expect(props.color.defaultValue).toMatchObject({ value: '"#333"' })
66+
})
67+
it('should the component has fourteen props', () => {
68+
expect(Object.keys(props).length).toEqual(14)
69+
})
7070

71-
it('should span to be string|number', () => {
72-
expect(docButton['props']['span']['type']['name']).toEqual('string|number')
73-
})
71+
it('should the component has propsAnother prop default equal "blue"', () => {
72+
expect(props.propsAnother.defaultValue).toMatchObject({ value: '"blue"' })
73+
})
7474

75-
it("should span has as description 'Number of columns (1-12) the column should span.'", () => {
76-
expect(docButton['props']['span']['description']).toEqual(
77-
'Number of columns (1-12) the column should span.'
78-
)
79-
})
75+
it('should span to be string|number', () => {
76+
expect(props.span.type).toEqual({ name: 'string|number' })
77+
})
8078

81-
it("should span has as description 'Sm breakpoint and above'", () => {
82-
expect(docButton['props']['spanSm']['description']).toEqual('Sm breakpoint and above')
83-
})
79+
it("should span has as description 'Number of columns (1-12) the column should span.'", () => {
80+
expect(props.span.description).toEqual('Number of columns (1-12) the column should span.')
81+
})
8482

85-
it("should spanMd has as description 'Md breakpoint and above'", () => {
86-
expect(docButton['props']['spanMd']['description']).toEqual('Md breakpoint and above')
87-
})
83+
it("should span has as description 'Sm breakpoint and above'", () => {
84+
expect(props.spanSm.description).toEqual('Sm breakpoint and above')
85+
})
8886

89-
it('should spanSm to be string|number', () => {
90-
expect(docButton['props']['spanSm']['type']['name']).toEqual('string|number')
91-
})
87+
it("should spanMd has as description 'Md breakpoint and above'", () => {
88+
expect(props.spanMd.description).toEqual('Md breakpoint and above')
89+
})
9290

93-
it('should set funcDefault prop as a function (type "func")', () => {
94-
expect(docButton['props']['funcDefault']['type']['name']).toEqual('func')
95-
})
91+
it('should spanSm to be string|number', () => {
92+
expect(props.spanSm.type).toEqual({ name: 'string|number' })
93+
})
9694

97-
it('should prop1 to be string', () => {
98-
expect(docButton['props']['prop1']['type']).toMatchObject({name:'string'})
99-
})
95+
it('should set funcDefault prop as a function (type "func")', () => {
96+
expect(props.funcDefault.type).toEqual({ name: 'func' })
97+
})
10098

101-
it('should example to be boolean', () => {
102-
expect(docButton['props']['example']['type']['name']).toEqual('boolean')
103-
})
99+
it('should prop1 to be string', () => {
100+
expect(props.prop1.type).toMatchObject({ name: 'string' })
101+
})
104102

105-
it('should value default example to be false', () => {
106-
expect(docButton['props']['example']['defaultValue']['value']).toEqual('false')
107-
})
103+
it('should example to be boolean', () => {
104+
expect(props.example.type).toEqual({ name: 'boolean' })
105+
})
108106

109-
it('should value default example props description to be The example props', () => {
110-
expect(docButton['props']['example']['description']).toEqual('The example props')
111-
})
107+
it('should value default example to be false', () => {
108+
expect(props.example.defaultValue).toMatchObject({ value: 'false' })
109+
})
112110

113-
it('should v-model to be string', () => {
114-
expect(docButton['props']['v-model']['type']['name']).toEqual('string')
115-
})
111+
it('should value default example props description to be The example props', () => {
112+
expect(props.example.description).toEqual('The example props')
113+
})
116114

117-
it('should value default v-model to be example model', () => {
118-
expect(docButton['props']['v-model']['defaultValue']['value']).toEqual('"example model"')
119-
})
115+
it('should v-model to be string', () => {
116+
expect(props['v-model'].type).toEqual({ name: 'string' })
117+
})
120118

121-
it('should value default v-model props description to be Model example2', () => {
122-
expect(docButton['props']['v-model']['description']).toEqual('Model example2')
123-
})
119+
it('should value default v-model to be example model', () => {
120+
expect(props['v-model'].defaultValue).toMatchObject({ value: '"example model"' })
121+
})
124122

125-
it('should propE to be string', () => {
126-
expect(docButton['props']['propE']['type']['name']).toEqual('object')
127-
})
123+
it('should value default v-model props description to be Model example2', () => {
124+
expect(props['v-model'].description).toEqual('Model example2')
125+
})
128126

129-
it('should value default propE to be a funtion', () => {
130-
const functionNoSpaceNoReturn = docButton['props']['propE']['defaultValue']['value'].replace(/[ \n\r]/g, '')
131-
expect(functionNoSpaceNoReturn).toEqual(`()=>{return{message:'hello'};}`)
132-
expect(docButton['props']['propE']['defaultValue']['func']).toBeTruthy()
133-
})
127+
it('should propE to be string', () => {
128+
expect(props.propE.type).toEqual({ name: 'object' })
129+
})
134130

135-
it('should example3 to be number', () => {
136-
expect(docButton['props']['example3']).toMatchObject({type:{name:'number'}})
137-
})
131+
it('should value default propE to be a funtion', () => {
132+
const dv = props.propE.defaultValue
133+
const functionNoSpaceNoReturn = dv ? dv.value.replace(/[ \n\r]/g, '') : ''
134+
expect(functionNoSpaceNoReturn).toEqual(`()=>{return{message:'hello'};}`)
135+
expect(dv ? dv.func : false).toBeTruthy()
136+
})
138137

139-
it('should value default example3 to be 16', () => {
140-
expect(docButton['props']['example3']['defaultValue']['value']).toEqual('16')
141-
})
138+
it('should example3 to be number', () => {
139+
expect(props.example3).toMatchObject({ type: { name: 'number' } })
140+
})
142141

143-
it('should value default example3 props description to be The example3 props', () => {
144-
expect(docButton['props']['example3']['description']).toEqual('The example3 props')
145-
})
142+
it('should value default example3 to be 16', () => {
143+
expect(props.example3.defaultValue).toMatchObject({ value: '16' })
144+
})
146145

147-
it('should onCustomClick to be ignored', () => {
148-
expect(docButton['props']['onCustomClick']['tags']['ignore']).toBeDefined()
149-
})
146+
it('should value default example3 props description to be The example3 props', () => {
147+
expect(props.example3.description).toEqual('The example3 props')
148+
})
149+
150+
it('should onCustomClick to be ignored', () => {
151+
expect(props.onCustomClick.tags.ignore).toBeDefined()
152+
})
150153

151-
it('should prop1 to be ignored', () => {
152-
expect(docButton['props']['prop1']['tags']['ignore']).toBeDefined()
154+
it('should prop1 to be ignored', () => {
155+
expect(props.prop1.tags.ignore).toBeDefined()
156+
})
153157
})
154158

155159
it('should the component has one event', () => {
156-
expect(Object.keys(docButton['events']).length).toEqual(1)
160+
expect(Object.keys(docButton.events).length).toEqual(1)
157161
})
158162

159163
it('should the component has event, it called success', () => {
160-
expect(docButton['events']['success']).not.toBeUndefined()
164+
expect(docButton.events.success).not.toBeUndefined()
161165
})
162166

163167
it('should the description of success event is Success event.', () => {
164-
expect(docButton['events']['success']['description']).toEqual('Success event.')
168+
expect(docButton.events.success.description).toEqual('Success event.')
165169
})
166170

167171
it('should have a slot.', () => {
168-
expect(Object.keys(docButton['slots']).length).toEqual(1)
172+
expect(Object.keys(docButton.slots).length).toEqual(1)
169173
})
170174

171175
it('should have a default slot.', () => {
172-
expect(typeof docButton['slots']['default'] !== 'undefined').toBe(true)
176+
expect(typeof docButton.slots.default !== 'undefined').toBe(true)
173177
})
174178

175179
it('the default slot should have "Use this slot default" as description', () => {
176-
expect(docButton['slots']['default']['description']).toEqual('Use this slot default')
180+
expect(docButton.slots.default.description).toEqual('Use this slot default')
177181
})
178182

179183
it('should match the snapshot', () => {

0 commit comments

Comments
 (0)