mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
Eslint: Modernize tests for ES6
Change-Id: I3600afd2eeacddc8e1c983eaad0a96e0755c7ba5
This commit is contained in:
parent
c4fc73465f
commit
96baf5db50
|
@ -1,22 +1,14 @@
|
|||
{
|
||||
"root": true,
|
||||
"extends": [
|
||||
"../.eslintrc.json"
|
||||
"../.eslintrcEs6.json"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
"es-x/no-object-assign": "off",
|
||||
"es-x/no-arrow-functions": "warn",
|
||||
"es-x/no-async-functions": "warn",
|
||||
"es-x/no-block-scoped-variables": "warn",
|
||||
"es-x/no-default-parameters": "warn",
|
||||
"es-x/no-destructuring": "warn",
|
||||
"es-x/no-promise": "warn",
|
||||
"es-x/no-property-shorthands": "warn",
|
||||
"es-x/no-rest-spread-properties": "warn",
|
||||
"es-x/no-template-literals": "warn"
|
||||
"es-x/no-rest-spread-properties": "off",
|
||||
"es-x/no-async-functions": "off"
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
|
|
|
@ -13,6 +13,7 @@ const MW_EXPERIMENT_PARAM = {
|
|||
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @return {AB.WebABTest}
|
||||
*/
|
||||
function createInstance( props = {} ) {
|
||||
const mergedProps = /** @type {AB.WebABTestProps} */ ( Object.assign( {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Pinnable header renders 1`] = `
|
||||
"
|
||||
<div id=\\"pinned-container\\">
|
||||
"<div id=\\"pinned-container\\">
|
||||
|
||||
</div>
|
||||
<div class=\\"vector-dropdown\\">
|
||||
|
@ -12,14 +11,14 @@ exports[`Pinnable header renders 1`] = `
|
|||
</label>
|
||||
<div class=\\"vector-menu-content\\">
|
||||
<div id=\\"unpinned-container\\">
|
||||
<div id=\\"pinnable-element\\"> <div class=\\"vector-pinnable-header pinnable-element-pinnable-header vector-pinnable-header-unpinned\\" data-feature-name=\\"pinned\\" data-pinnable-element-id=\\"pinnable-element\\">
|
||||
<div id=\\"pinnable-element\\"><div class=\\"vector-pinnable-header pinnable-element-pinnable-header vector-pinnable-header-unpinned\\" data-feature-name=\\"pinned\\" data-pinnable-element-id=\\"pinnable-element\\">
|
||||
<div class=\\"vector-pinnable-header-label\\">simple pinnable element</div>
|
||||
<button class=\\"vector-pinnable-header-toggle-button vector-pinnable-header-pin-button\\" data-event-name=\\"pinnable-header.pinnable-element.pin\\">pin</button>
|
||||
<button class=\\"vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button\\" data-event-name=\\"pinnable-header.pinnable-element.unpin\\">unpin</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
"
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -17,14 +17,14 @@ describe( 'deferUntilFrame.js', () => {
|
|||
spy.mockRestore();
|
||||
} );
|
||||
|
||||
it( 'does not fire rAF if `0` is passed', done => {
|
||||
it( 'does not fire rAF if `0` is passed', ( done ) => {
|
||||
deferUntilFrame( () => {
|
||||
expect( spy ).toHaveBeenCalledTimes( 0 );
|
||||
done();
|
||||
}, 0 );
|
||||
} );
|
||||
|
||||
it( 'fires rAF the specified number of times', done => {
|
||||
it( 'fires rAF the specified number of times', ( done ) => {
|
||||
deferUntilFrame( () => {
|
||||
expect( spy ).toHaveBeenCalledTimes( 3 );
|
||||
done();
|
||||
|
|
|
@ -53,8 +53,6 @@ describe( 'fetch() using window.fetch', () => {
|
|||
test( '200 without init param passed', async () => {
|
||||
const { fetch } = fetchJson( url );
|
||||
const json = await fetch;
|
||||
|
||||
// eslint-disable-next-line compat/compat
|
||||
const controller = new AbortController();
|
||||
expect( json ).toStrictEqual( { pages: [] } );
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ const pinnableElement = require( '../../resources/skins.vector.es6/pinnableEleme
|
|||
*/
|
||||
Object.defineProperty( window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: jest.fn().mockImplementation( query => ( {
|
||||
value: jest.fn().mockImplementation( ( query ) => ( {
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
|
@ -52,10 +52,9 @@ const movableData = { ...simpleData, ...{
|
|||
const initializeHTML = ( headerData ) => {
|
||||
pinnedStatus = headerData[ 'is-pinned' ];
|
||||
const pinnableHeaderHTML = mustache.render( pinnableHeaderTemplate, headerData );
|
||||
const pinnableElementHTML = `<div id="pinnable-element"> ${ pinnableHeaderHTML } </div>`;
|
||||
document.body.innerHTML = `
|
||||
<div id="pinned-container">
|
||||
${ headerData[ 'is-pinned' ] ? pinnableElementHTML : '' }
|
||||
const pinnableElementHTML = `<div id="pinnable-element">${pinnableHeaderHTML}</div>`;
|
||||
document.body.innerHTML = `<div id="pinned-container">
|
||||
${headerData[ 'is-pinned' ] ? pinnableElementHTML : ''}
|
||||
</div>
|
||||
<div class="vector-dropdown">
|
||||
<input type="checkbox" id="checkbox" class="vector-menu-checkbox">
|
||||
|
@ -64,11 +63,11 @@ const initializeHTML = ( headerData ) => {
|
|||
</label>
|
||||
<div class="vector-menu-content">
|
||||
<div id="unpinned-container">
|
||||
${ !headerData[ 'is-pinned' ] ? pinnableElementHTML : '' }
|
||||
${!headerData[ 'is-pinned' ] ? pinnableElementHTML : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
`;
|
||||
};
|
||||
|
||||
describe( 'Pinnable header', () => {
|
||||
|
@ -101,13 +100,11 @@ describe( 'Pinnable header', () => {
|
|||
const unpinButton = /** @type {HTMLElement} */ ( document.querySelector( '.vector-pinnable-header-unpin-button' ) );
|
||||
const pinnableElem = /** @type {HTMLElement} */ ( document.getElementById( simpleData[ 'data-pinnable-element-id' ] ) );
|
||||
|
||||
/* eslint-disable no-restricted-properties */
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'unpinned-container' );
|
||||
pinButton.click();
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'unpinned-container' );
|
||||
unpinButton.click();
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'unpinned-container' );
|
||||
/* eslint-enable no-restricted-properties */
|
||||
} );
|
||||
|
||||
test( 'moves pinnable element when data attributes are defined', () => {
|
||||
|
@ -117,13 +114,11 @@ describe( 'Pinnable header', () => {
|
|||
const unpinButton = /** @type {HTMLElement} */ ( document.querySelector( '.vector-pinnable-header-unpin-button' ) );
|
||||
const pinnableElem = /** @type {HTMLElement} */ ( document.getElementById( movableData[ 'data-pinnable-element-id' ] ) );
|
||||
|
||||
/* eslint-disable no-restricted-properties */
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'unpinned-container' );
|
||||
pinButton.click();
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'pinned-container' );
|
||||
unpinButton.click();
|
||||
expect( pinnableElem.parentElement && pinnableElem.parentElement.id ).toBe( 'unpinned-container' );
|
||||
/* eslint-enable no-restricted-properties */
|
||||
} );
|
||||
|
||||
test( 'calls features.toggle() when toggle is pressed', () => {
|
||||
|
|
|
@ -72,7 +72,6 @@ describe( 'restApiSearchClient', () => {
|
|||
2
|
||||
).fetch;
|
||||
|
||||
/* eslint-disable-next-line compat/compat */
|
||||
const controller = new AbortController();
|
||||
|
||||
expect( searchResult.query ).toStrictEqual( 'media' );
|
||||
|
@ -103,7 +102,6 @@ describe( 'restApiSearchClient', () => {
|
|||
'thereIsNothingLikeThis'
|
||||
).fetch;
|
||||
|
||||
/* eslint-disable-next-line compat/compat */
|
||||
const controller = new AbortController();
|
||||
expect( searchResult.query ).toStrictEqual( 'thereIsNothingLikeThis' );
|
||||
expect( searchResult.results ).toBeTruthy();
|
||||
|
|
|
@ -166,7 +166,7 @@ const sectionObserverFn = () => ( {
|
|||
describe( 'Table of contents re-rendering', () => {
|
||||
const mockMwHook = () => {
|
||||
/** @type {Object.<string, Function>} */
|
||||
let callback = {};
|
||||
const callback = {};
|
||||
// @ts-ignore
|
||||
jest.spyOn( mw, 'hook' ).mockImplementation( ( name ) => {
|
||||
|
||||
|
|
|
@ -314,7 +314,6 @@ describe( 'Table of contents', () => {
|
|||
|
||||
test( 're-renders toc when wikipage.tableOfContents hook is fired with sections', async () => {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line compat/compat
|
||||
jest.spyOn( mw.loader, 'using' ).mockImplementation( () => Promise.resolve() );
|
||||
// @ts-ignore
|
||||
mw.template.getCompiler = () => {};
|
||||
|
|
Loading…
Reference in a new issue