Skip to content

Commit 5559687

Browse files
authored
Merge pull request #132 from magento-trigger/AC-391
AC-391: Static test to cover "deprecated" jQuery methods
2 parents 1be74dc + 38b3319 commit 5559687

22 files changed

+385
-75
lines changed

Magento2/Tests/Eslint/AndSelfTest.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
$(document).ready(function () {
2-
'use strict';
1+
define([
2+
'jquery',
3+
], function ($) {
4+
$(function () {
5+
'use strict';
36

4-
$('div').find('p').andSelf().addClass('border');
7+
$('div').find('p').andSelf().addClass('border');
8+
});
59
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
$(document).ready(function () {
2-
'use strict';
1+
define([
2+
'jquery',
3+
], function ($) {
4+
$(function () {
5+
'use strict';
36

4-
$('.btn1').bind('click');
7+
$('.btn1').bind('click');
8+
});
59
});

Magento2/Tests/Eslint/ClickEventShorthandTest.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

Magento2/Tests/Eslint/ClickEventShorthandTest.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
$(document).ready(function () {
2-
'use strict';
1+
define([
2+
'jquery',
3+
], function ($) {
4+
$(function () {
5+
'use strict';
36

4-
$('table').delegate('td', 'click', function () {
5-
$(this).toggleClass('chosen');
7+
$('table').delegate('td', 'click', function () {
8+
$(this).toggleClass('chosen');
9+
});
610
});
711
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
define([
2+
'jquery',
3+
], function (jQuery) {
4+
$(function () {
5+
'use strict';
6+
7+
jQuery.extend(jQuery.expr[':'], {});
8+
jQuery.extend(jQuery.expr.filters, {});
9+
});
10+
});
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 DeprecatedExprTest
12+
*
13+
* Test Eslint Rule: jquery-no-deprecated-expr.js
14+
*/
15+
class DeprecatedExprTest extends AbstractEslintTestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$this->assertFileContainsError(
20+
'DeprecatedExprTest.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+
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
$(document).ready(function () {
2-
'use strict';
3-
4-
$('#result').load('ajax/test.html');
1+
define([
2+
'jquery',
3+
], function (jQuery) {
4+
jQuery(document).ready(function () {
5+
'use strict';
6+
jQuery('#result').unload(function () {
7+
});
8+
});
59
});
10+

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define([
2+
'jquery',
3+
], function ($) {
4+
$(function () {
5+
'use strict';
6+
7+
$('#result').blur();
8+
$.fn.focus(function () {
9+
});
10+
});
11+
});

0 commit comments

Comments
 (0)