Skip to content

Commit 8949ab0

Browse files
committed
jest: Fail on Vue and other warnings
If console.warn/console.error are invoked, fail the test. This is useful for catching Vue warnings before they're merged. Fix various warnings triggered by tests. Bug: T323252 Change-Id: I1c0064f8dd1fcd050049df2811eafbec63f09717
1 parent 6da06f5 commit 8949ab0

File tree

12 files changed

+186
-31
lines changed

12 files changed

+186
-31
lines changed

jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ module.exports = {
3939
],
4040
setupFiles: [
4141
'./jest.setup.js'
42+
],
43+
setupFilesAfterEnv: [
44+
'./jest.setupAfterEnv.js'
4245
]
4346
};

jest.setupAfterEnv.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const failOnConsole = require( 'jest-fail-on-console' );
4+
5+
failOnConsole();

modules/ext.growthExperiments.Homepage.NewImpact/components/NewImpactVue.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ describe( 'NewImpactVue', () => {
108108
global: {
109109
provide: {
110110
RENDER_MODE: 'desktop',
111-
RELEVANT_USER_USERNAME: 'Alice'
111+
RELEVANT_USER_USERNAME: 'Alice',
112+
$log: jest.fn()
112113
},
113114
mocks: {
114115
$filters: {

modules/ext.growthExperiments.Homepage.NewImpact/components/NoEditsDisplay.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ describe( 'NoEditsDisplay', () => {
3333
'overlay-summary'
3434
];
3535
for ( const mode of modes ) {
36-
it( `displays appropiate text when disabled (${mode})`, () => {
36+
it( `displays appropriate text when disabled (${mode})`, () => {
3737
const wrapper = renderComponent( {
3838
userName: 'Alice',
3939
isDisabled: true
4040
}, mode );
4141

4242
expect( wrapper.element ).toMatchSnapshot();
4343
} );
44-
it( `displays appropiate text when activated (${mode})`, () => {
44+
it( `displays appropriate text when activated (${mode})`, () => {
4545
const wrapper = renderComponent( {
4646
userName: 'Alice',
4747
isActivated: true

modules/ext.growthExperiments.Homepage.NewImpact/components/NoEditsDisplay.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ module.exports = exports = {
101101
},
102102
computed: {
103103
subtextFontWeight() {
104-
return this.renderMode !== 'overlay-summary' && 'bold';
104+
return this.renderMode !== 'overlay-summary' ? 'bold' : null;
105105
},
106106
footerFontSize() {
107-
return this.renderMode !== 'desktop' && 'sm';
107+
return this.renderMode !== 'desktop' ? 'sm' : null;
108108
}
109109
}
110110
};

modules/ext.growthExperiments.Homepage.NewImpact/components/__snapshots__/NoEditsDisplay.test.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`NoEditsDisplay displays appropiate text when activated (desktop) 1`] = `
3+
exports[`NoEditsDisplay displays appropriate text when activated (desktop) 1`] = `
44
<div
55
class="ext-growthExperiments-NoEditsDisplay--desktop"
66
>
@@ -40,7 +40,7 @@ exports[`NoEditsDisplay displays appropiate text when activated (desktop) 1`] =
4040
</div>
4141
`;
4242

43-
exports[`NoEditsDisplay displays appropiate text when activated (overlay) 1`] = `
43+
exports[`NoEditsDisplay displays appropriate text when activated (overlay) 1`] = `
4444
<div
4545
class="ext-growthExperiments-NoEditsDisplay--overlay"
4646
>
@@ -89,7 +89,7 @@ exports[`NoEditsDisplay displays appropiate text when activated (overlay) 1`] =
8989
</div>
9090
`;
9191

92-
exports[`NoEditsDisplay displays appropiate text when activated (overlay-summary) 1`] = `
92+
exports[`NoEditsDisplay displays appropriate text when activated (overlay-summary) 1`] = `
9393
<div
9494
class="ext-growthExperiments-NoEditsDisplay--overlay-summary"
9595
>
@@ -129,7 +129,7 @@ exports[`NoEditsDisplay displays appropiate text when activated (overlay-summary
129129
</div>
130130
`;
131131

132-
exports[`NoEditsDisplay displays appropiate text when disabled (desktop) 1`] = `
132+
exports[`NoEditsDisplay displays appropriate text when disabled (desktop) 1`] = `
133133
<div
134134
class="ext-growthExperiments-NoEditsDisplay--desktop"
135135
>
@@ -171,7 +171,7 @@ exports[`NoEditsDisplay displays appropiate text when disabled (desktop) 1`] = `
171171
</div>
172172
`;
173173

174-
exports[`NoEditsDisplay displays appropiate text when disabled (overlay) 1`] = `
174+
exports[`NoEditsDisplay displays appropriate text when disabled (overlay) 1`] = `
175175
<div
176176
class="ext-growthExperiments-NoEditsDisplay--overlay"
177177
>
@@ -213,7 +213,7 @@ exports[`NoEditsDisplay displays appropiate text when disabled (overlay) 1`] = `
213213
</div>
214214
`;
215215

216-
exports[`NoEditsDisplay displays appropiate text when disabled (overlay-summary) 1`] = `
216+
exports[`NoEditsDisplay displays appropriate text when disabled (overlay-summary) 1`] = `
217217
<div
218218
class="ext-growthExperiments-NoEditsDisplay--overlay-summary"
219219
>

modules/ext.growthExperiments.MentorDashboard/components/MenteeOverview/MenteeFiltersForm.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
<cdx-button
8484
class="ext-growthExperiments-utils__pull-right"
8585
form="mentee-filters-form"
86-
type="submit">
86+
type="primary"
87+
>
8788
{{
8889
$i18n( 'growthexperiments-mentor-dashboard-mentee-overview-add-filter-submit' ).text()
8990
}}

modules/ext.growthExperiments.MentorDashboard/components/MenteeOverview/MenteeOverview.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
jest.mock( '../icons.json', () => ( {} ), { virtual: true } );
1+
jest.mock( '../icons.json', () => ( {
2+
cdxIconError: ''
3+
} ), { virtual: true } );
24
const { shallowMount } = require( '@vue/test-utils' );
35
const Vuex = require( 'vuex' );
46
const MenteeOverview = require( './MenteeOverview.vue' );

modules/ext.growthExperiments.MentorDashboard/components/MenteeOverview/NoResults.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<script>
1818
const { CdxIcon } = require( '@wikimedia/codex' );
19+
const { cdxIconError } = require( '../icons.json' );
1920
2021
// @vue/component
2122
module.exports = exports = {
@@ -27,7 +28,7 @@ module.exports = exports = {
2728
description: { type: String, default: null },
2829
iconLabel: { type: String, required: true },
2930
text: { type: String, required: true },
30-
icon: { type: String, required: true }
31+
icon: { type: String, required: true, default: cdxIconError }
3132
}
3233
};
3334
</script>

modules/ext.growthExperiments.MentorDashboard/components/MenteeOverview/__snapshots__/MenteeFiltersForm.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ exports[`MenteeFiltersForm it should localise numbers in the recent edits 1`] =
163163
class="ext-growthExperiments-MenteeFiltersForm__form-group ext-growthExperiments-MenteeFiltersForm__form-actions"
164164
>
165165
<button
166-
class="cdx-button cdx-button--action-default cdx-button--type-submit cdx-button--framed ext-growthExperiments-utils__pull-right"
166+
class="cdx-button cdx-button--action-default cdx-button--type-primary cdx-button--framed ext-growthExperiments-utils__pull-right"
167167
form="mentee-filters-form"
168168
>
169169

0 commit comments

Comments
 (0)