Skip to content

Commit 1547f2a

Browse files
committed
AC-391: Static test to cover "deprecated" jQuery methods
- Improved static test coverage: - Removed jQuery.load(handler) test as jQuery.load(handler) is a valid function - Removed jQuery.error(handler) test as jQuery.error(msg) is a valid function - Added static tests for $.isFunction, $.type, $.parseJson, $.isArray - Added test for $.expr[':'] and $.expr.filters
1 parent 90ee488 commit 1547f2a

19 files changed

+208
-22
lines changed

Magento2/Tests/Eslint/AbstractEslintTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractEslintTestCase extends TestCase
2323
protected function assertFileContainsError(string $testFile, array $expectedMessages): void
2424
{
2525
exec(
26-
'npm run eslint -- Magento2/Tests/Eslint/' . $testFile,
26+
'npm run eslint -- Magento2/Tests/Eslint/' . $testFile . ' 2>&1',
2727
$output
2828
);
2929

Magento2/Tests/Eslint/AndSelfTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$(document).ready(function () {
1+
$(function () {
22
'use strict';
33

44
$('div').find('p').andSelf().addClass('border');

Magento2/Tests/Eslint/BindUnbindTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$(document).ready(function () {
1+
$(function () {
22
'use strict';
33

44
$('.btn1').bind('click');
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
$(document).ready(function () {
1+
$(function () {
22
'use strict';
33

4-
$('input').blur();
4+
$('#result').blur();
5+
$.fn.focus(function () {});
56
});

Magento2/Tests/Eslint/ClickEventShorthandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public function testExecute(): void
1818
{
1919
$this->assertFileContainsError(
2020
'ClickEventShorthandTest.js',
21-
['Instead of .blur(fn) use .on("blur", fn). Instead of .blur() use .trigger("blur")']
21+
[
22+
'Instead of .blur(fn) use .on("blur", fn). Instead of .blur() use .trigger("blur")',
23+
'Instead of .focus(fn) use .on("focus", fn). Instead of .focus() use .trigger("focus")',
24+
]
2225
);
2326
}
24-
}
27+
}

Magento2/Tests/Eslint/DelegateUndelegateTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$(document).ready(function () {
1+
$(function () {
22
'use strict';
33

44
$('table').delegate('td', 'click', function () {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
$(document).ready(function () {
22
'use strict';
3-
4-
$('#result').load('ajax/test.html');
3+
$('#result').unload(function () {});
54
});

Magento2/Tests/Eslint/EventShorthandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public function testExecute(): void
1818
{
1919
$this->assertFileContainsError(
2020
'EventShorthandTest.js',
21-
['jQuery.load() was removed, use .on("load", fn) instead']
21+
[
22+
'jQuery.unload() was removed, use .on("unload", fn) instead',
23+
'jQuery.ready(handler) is deprecated and should be replaced with jQuery(handler)'
24+
]
2225
);
2326
}
24-
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$(function () {
2+
'use strict';
3+
4+
$.extend($.expr[':'], {});
5+
jQuery.extend($.expr.filters, {});
6+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Eslint;
9+
10+
/**
11+
* Class EventShorthandTest
12+
*
13+
* Test Eslint Rule: jquery-no-event-shorthand.js
14+
*/
15+
class MiscDeprecatedExprTest extends AbstractEslintTestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$this->assertFileContainsError(
20+
'MiscDeprecatedExprTest.js',
21+
[
22+
'jQuery.expr[":"] is deprecated; Use jQuery.expr.pseudos instead',
23+
'jQuery.expr.filters is deprecated; Use jQuery.expr.pseudos instead'
24+
]
25+
);
26+
}
27+
}

0 commit comments

Comments
 (0)