Skip to content

Commit 61151b5

Browse files
Update @vue/test-utils
I upgraded @vue/test-utils to the latest version, `v1.0.0-beta.31`. We were previously on `v1.0.0-beta25`, here's the changelog: - https://github.com/vuejs/vue-test-utils/releases This upgrade broke a bunch of tests; our tests had to refactored to run asynchronously, here are some links regarding that: - vuejs/vue-test-utils#1137 - https://vue-test-utils.vuejs.org/guides/#writing-asynchronous-tests-using-nexttick-new Refs: #2380
1 parent 1a97d53 commit 61151b5

File tree

12 files changed

+277
-119
lines changed

12 files changed

+277
-119
lines changed

spec/javascript/admin/content-settings/components/Review.spec.js

+102-44
Large diffs are not rendered by default.

spec/javascript/admin/dashboard/components/MentorsSection.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,24 @@ describe('Admin Dashboard - MentorSection component', () => {
178178
expect(returningChart.find(PieChart).exists()).toBe(true)
179179
})
180180

181-
it('hides the mentors count label if the mentors total is not found', () => {
181+
it('hides the mentors count label if the mentors total is not found', async () => {
182182
wrapper.vm.totals = {}
183183

184+
await wrapper.vm.$nextTick()
185+
184186
expect(wrapper.find('h3 span').exists()).toBe(false)
185187
})
186188

187-
it('hides the mentors count label if the hideTotal prop is true', () => {
189+
it('hides the mentors count label if the hideTotal prop is true', async () => {
188190
wrapper.setProps({
189191
hideTotal: true,
190192
})
191193

194+
await wrapper.vm.$nextTick()
195+
192196
expect(wrapper.find('h3 span').exists()).toBe(false)
193197
})
194198

195199
})
196200

197-
})
201+
})

spec/javascript/admin/dashboard/components/StudentsSection.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,24 @@ describe('Admin Dashboard - StudentsSection component', () => {
178178
expect(returningChart.find(PieChart).exists()).toBe(true)
179179
})
180180

181-
it('hides the students count label if the students total is not found', () => {
181+
it('hides the students count label if the students total is not found', async () => {
182182
wrapper.vm.totals = {}
183183

184+
await wrapper.vm.$nextTick()
185+
184186
expect(wrapper.find('h3 span').exists()).toBe(false)
185187
})
186188

187-
it('hides the students count label if the hideTotal prop is true', () => {
189+
it('hides the students count label if the hideTotal prop is true', async () => {
188190
wrapper.setProps({
189191
hideTotal: true,
190192
})
191193

194+
await wrapper.vm.$nextTick()
195+
192196
expect(wrapper.find('h3 span').exists()).toBe(false)
193197
})
194198

195199
})
196200

197-
})
201+
})

spec/javascript/admin/dashboard/components/TopCountriesSection.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,24 @@ describe('Admin Dashboard - TopCountriesSection component', () => {
119119
expect(wrapper.find(BarChart).exists()).toBe(true)
120120
})
121121

122-
it('hides the top countries count label if the top countries total is not found', () => {
122+
it('hides the top countries count label if the top countries total is not found', async () => {
123123
wrapper.vm.totals = {}
124124

125+
await wrapper.vm.$nextTick()
126+
125127
expect(wrapper.find('h3 span').exists()).toBe(false)
126128
})
127129

128-
it('hides the top countries count label if the hideTotal prop is true', () => {
130+
it('hides the top countries count label if the hideTotal prop is true', async () => {
129131
wrapper.setProps({
130132
hideTotal: true,
131133
})
132134

135+
await wrapper.vm.$nextTick()
136+
133137
expect(wrapper.find('h3 span').exists()).toBe(false)
134138
})
135139

136140
})
137141

138-
})
142+
})

spec/javascript/components/DropDown.spec.js

+18-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TransitionStub, shallowMount } from '@vue/test-utils'
1+
import { enableAutoDestroy, TransitionStub, shallowMount } from '@vue/test-utils'
22

33
import DropDown from 'components/DropDown'
44
import Icon from 'components/Icon'
@@ -26,9 +26,6 @@ describe('DropDown Vue component', () => {
2626
</div>
2727
`,
2828
},
29-
stubs: {
30-
transition: TransitionStub,
31-
},
3229
})
3330
})
3431

@@ -128,7 +125,7 @@ describe('DropDown Vue component', () => {
128125
expect(wrapper.classes('drop-down')).toBe(true)
129126
})
130127

131-
it('contains a link that toggles the drop down open and closed', (done) => {
128+
it('contains a link that toggles the drop down open and closed', async () => {
132129
const toggleCollapseSpy = spyOn(wrapper.vm, 'toggleCollapse')
133130
.and.callThrough()
134131
const toggleLink = wrapper.find('a')
@@ -141,42 +138,41 @@ describe('DropDown Vue component', () => {
141138
expect(toggleCollapseSpy).not.toHaveBeenCalled()
142139

143140
toggleLink.element.click()
141+
await wrapper.vm.$nextTick()
144142

145-
wrapper.vm.$nextTick(() => {
146-
expect(dropDownContent.isVisible()).toBe(true)
147-
expect(toggleCollapseSpy).toHaveBeenCalledTimes(1)
143+
expect(dropDownContent.isVisible()).toBe(true)
144+
expect(toggleCollapseSpy).toHaveBeenCalledTimes(1)
148145

149-
toggleLink.element.click()
146+
toggleLink.element.click()
147+
await wrapper.vm.$nextTick()
150148

151-
wrapper.vm.$nextTick(() => {
152-
expect(dropDownContent.isVisible()).toBe(false)
153-
expect(toggleCollapseSpy).toHaveBeenCalledTimes(2)
154-
done()
155-
})
156-
})
149+
expect(dropDownContent.isVisible()).toBe(false)
150+
expect(toggleCollapseSpy).toHaveBeenCalledTimes(2)
157151
})
158152

159-
it('contains a caret icon which changes based on expanded/collpased state', () => {
153+
it('contains a caret icon which changes based on expanded/collpased state', async () => {
160154
const caretIcon = wrapper.find(Icon)
161155

162156
expect(caretIcon.exists()).toBe(true)
163157

164158
wrapper.setData({ expanded: true })
159+
await wrapper.vm.$nextTick()
165160

166161
expect(caretIcon.props('title')).toEqual('Collapse')
167162
expect(caretIcon.props('name')).toEqual('caret-up')
168163
expect(caretIcon.props('color')).toEqual('000000')
169164
expect(caretIcon.props('size')).toEqual(12)
170165

171166
wrapper.setData({ expanded: false })
167+
await wrapper.vm.$nextTick()
172168

173169
expect(caretIcon.props('title')).toEqual('Expand')
174170
expect(caretIcon.props('name')).toEqual('caret-down')
175171
expect(caretIcon.props('color')).toEqual('000000')
176172
expect(caretIcon.props('size')).toEqual(12)
177173
})
178174

179-
it('uses the v-click-outside directive to collapse the drop down', (done) => {
175+
it('uses the v-click-outside directive to collapse the drop down', async () => {
180176
const dropDownContent = wrapper.find('.drop-down__content')
181177

182178
const divNode = document.createElement('div')
@@ -185,19 +181,17 @@ describe('DropDown Vue component', () => {
185181
document.body.appendChild(divNode)
186182

187183
wrapper.setData({ expanded: true })
184+
await wrapper.vm.$nextTick()
188185

189186
expect(dropDownContent.exists()).toBe(true)
190187
expect(dropDownContent.isVisible()).toBe(true)
191188

192189
divNode.click()
190+
await wrapper.vm.$nextTick()
193191

194-
wrapper.vm.$nextTick(() => {
195-
expect(dropDownContent.isVisible()).toBe(false)
196-
197-
divNode.remove()
192+
expect(dropDownContent.isVisible()).toBe(false)
198193

199-
done()
200-
})
194+
divNode.remove()
201195
})
202196
})
203-
})
197+
})

spec/javascript/components/IntegerInput.spec.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,25 @@ describe('IntegerInput Vue component', () => {
4444
});
4545
});
4646

47-
it('sets numericValue based on the value prop passed in', () => {
47+
it('sets numericValue based on the value prop passed in', async () => {
4848
const valueProps = [ 33, 99, 2808 ];
4949

50-
valueProps.forEach((value) => {
50+
valueProps.forEach(async (value) => {
5151
wrapper.setProps({ value });
5252

53+
await wrapper.vm.$nextTick()
54+
5355
expect(wrapper.vm.numericValue).toEqual(value);
5456
});
5557
});
5658

57-
it('sets the input name according to the input-name prop', () => {
59+
it('sets the input name according to the input-name prop', async () => {
5860
const inputName = 'this-is-a-test-input';
5961

6062
wrapper.setProps({ inputName });
6163

64+
await wrapper.vm.$nextTick()
65+
6266
expect(wrapper.find('input').attributes().name).toEqual(inputName);
6367
})
6468

@@ -141,7 +145,7 @@ describe('IntegerInput Vue component', () => {
141145
expect(wrapper.vm.numericValue).toEqual(expectedValue);
142146
});
143147

144-
it('does not change numericValue if value passed is not a number', () => {
148+
it('does not change numericValue if value passed is not a number', async () => {
145149
const minimum = 0;
146150
const maximum = 99;
147151
const expectedValue = 34;
@@ -152,6 +156,8 @@ describe('IntegerInput Vue component', () => {
152156
value: expectedValue,
153157
});
154158

159+
await wrapper.vm.$nextTick()
160+
155161
wrapper.vm.recalculateValue('test');
156162

157163
expect(wrapper.vm.numericValue).toEqual(expectedValue);
@@ -160,4 +166,4 @@ describe('IntegerInput Vue component', () => {
160166

161167
});
162168

163-
});
169+
});

spec/javascript/judge/scores/QuestionSection.spec.js

+12-20
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,16 @@ describe('Question comments section', () => {
5959
})
6060
})
6161

62-
test('saves comments after changes', (done) => {
62+
test('saves comments after changes', async() => {
6363
const storeCommitSpy = jest.spyOn(wrapper.vm.$store, 'commit')
6464

6565
wrapper.vm.comment.text = 'hello'
66+
await wrapper.vm.$nextTick()
6667

67-
wrapper.vm.$nextTick(() => {
68-
wrapper.vm.handleCommentChange()
68+
wrapper.vm.handleCommentChange()
69+
await wrapper.vm.$nextTick()
6970

70-
setImmediate(() => {
71-
expect(storeCommitSpy).toHaveBeenLastCalledWith('saveComment', 'ideation')
72-
done()
73-
})
74-
})
71+
expect(storeCommitSpy).toHaveBeenLastCalledWith('saveComment', 'ideation')
7572
})
7673

7774
test('debouncedCommentWatcher calls handleCommentChange', () => {
@@ -98,21 +95,16 @@ describe('Question comments section', () => {
9895
expect(handleCommentChangeSpy).toHaveBeenCalled()
9996
})
10097

101-
test('it resets the word count when the text is deleted', (done) => {
102-
wrapper.vm.$nextTick(() => {
103-
wrapper.vm.comment.text = 'hello beautiful world'
98+
test('it resets the word count when the text is deleted', async() => {
99+
wrapper.vm.comment.text = 'hello beautiful world'
100+
await wrapper.vm.$nextTick()
104101

105-
wrapper.vm.$nextTick(() => {
106-
expect(wrapper.vm.comment.word_count).toEqual(3)
102+
expect(wrapper.vm.comment.word_count).toEqual(3)
107103

108-
wrapper.vm.comment.text = ''
104+
wrapper.vm.comment.text = ''
105+
await wrapper.vm.$nextTick()
109106

110-
wrapper.vm.$nextTick(() => {
111-
expect(wrapper.vm.comment.word_count).toEqual(0)
112-
done()
113-
})
114-
})
115-
})
107+
expect(wrapper.vm.comment.word_count).toEqual(0)
116108
})
117109

118110
test('textarea should update comment text in store on change', (done) => {

spec/javascript/location/LocationForm.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ describe('location/components/LocationForm', () => {
105105
expect(suggestions.length).toEqual(3)
106106
})
107107

108-
it('is not visible if there are no suggestions present', () => {
108+
it('is not visible if there are no suggestions present', async () => {
109109
wrapper.setData({ suggestions: [] })
110110

111+
await wrapper.vm.$nextTick()
112+
111113
const suggestionsTable = wrapper.find({ ref: 'suggestionsTable' })
112114

113115
expect(suggestionsTable.exists()).toBe(false)
@@ -209,9 +211,11 @@ describe('location/components/LocationForm', () => {
209211
expect(savedLocationText).toContain('United States')
210212
})
211213

212-
it('is not visible if there is no saved location', () => {
214+
it('is not visible if there is no saved location', async () => {
213215
wrapper.setData({ savedLocation: null })
214216

217+
await wrapper.vm.$nextTick()
218+
215219
const savedLocationTable = wrapper.find({ ref: 'savedLocationTable' })
216220

217221
expect(savedLocationTable.exists()).toBe(false)
@@ -372,4 +376,4 @@ describe('location/components/LocationForm', () => {
372376
})
373377
})
374378
})
375-
})
379+
})

spec/javascript/mentor/DashboardHeader.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ describe("mentor/DashboardHeader.vue", () => {
4343
expect(dropDown.vm.label).toEqual("More Information")
4444
})
4545

46-
it("displays the currentAccount's name", () => {
46+
it("displays the currentAccount's name", async () => {
4747
defaultWrapper.vm.$store.commit('authenticated/htmlDataset', {
4848
currentAccount: '{"data":{"attributes":{"name":"Saul Goodman"}}}'
4949
})
5050

51+
await defaultWrapper.vm.$nextTick()
52+
5153
expect(defaultWrapper.find(
5254
'.dashboard-notices .grid__col-sm-6:nth-child(2)'
5355
).text()).toContain("Saul Goodman")
5456
})
5557

5658
describe("when the RA has not provided an intro", () => {
57-
it("displays the default left header", () => {
59+
it("displays the default left header", async () => {
5860
defaultWrapper.setProps({
5961
defaultTitle: "Mentor Dashboard",
6062
resourceLinks: [
@@ -66,6 +68,8 @@ describe("mentor/DashboardHeader.vue", () => {
6668
]
6769
})
6870

71+
await defaultWrapper.vm.$nextTick()
72+
6973
expect(defaultWrapper.find(
7074
'.dashboard-notices .grid__col-sm-6:first-child'
7175
).text()).toContain("Mentor Dashboard")
@@ -91,4 +95,4 @@ describe("mentor/DashboardHeader.vue", () => {
9195
expect(text).toContain("Technovation[MN]")
9296
})
9397
})
94-
})
98+
})

spec/javascript/registration/components/DataUseTerms.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ describe("Registration::Components::DataUseTerms.vue", () => {
5858
});
5959

6060
describe('submitButtonText', () => {
61-
it('sets the text on the "Next" button accoring to the prop value', () => {
61+
it('sets the text on the "Next" button according to the prop value', async () => {
6262
defaultWrapper.setProps({ submitButtonText: 'Submit' });
6363

64+
await defaultWrapper.vm.$nextTick()
65+
6466
const submitButtonText = defaultWrapper
6567
.find({ ref: 'dataUseTermsSubmitButton' }).text();
6668

@@ -75,4 +77,4 @@ describe("Registration::Components::DataUseTerms.vue", () => {
7577
});
7678
});
7779
});
78-
});
80+
});

0 commit comments

Comments
 (0)