Reputation: 2159
I'm running jquery 3.3.1, qunit 2.11.2, MacOS Chrome 87.0.4280.67
I have some code which works correctly when I run it in production, but fails under qunit. Investigating, it looks like $ has different values in those two environments. In this function:
function findSpiTemplate(page) {
const $html = $($.parseHTML(page));
// return $html.find("table[typeof='mw:Transclusion'][data-mw*='sock']").attr('data-mw');
console.log($);
return $html.find("table[typeof='mw:Transclusion']").filter(function() {
const x = $(this).attr('data-mw').match(/[sS]ock/);
return x;
}).attr('data-mw');
};
in my production environment, the console shows:
tag-check.js:49 ƒ (selector,context){return new jQuery.fn.init(selector,context);}
but under qunit I get:
ƒ (e,t){return new w.fn.init(e,t)}
My test driver is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Test Suite</title>
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/qunit/2.11.2/qunit.min.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/qunit/2.11.2/qunit.min.js"></script>
<!-- Tests need ajax support, so loading the non-slim version of jQuery. -->
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="tests.js"></script>
</body>
</html>
And my production code loads jquery with:
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
Upvotes: 1
Views: 54
Reputation: 2159
As usual, a good night's sleep brought some clarity. I still don't understand everything, but the big question of why I get:
ƒ (selector,context){return new jQuery.fn.init(selector,context);
vs
ƒ (e,t){return new w.fn.init(e,t)}
is that the later one is when I included the minimized version of jquery. And, yes, the script tag I showed above for my production code is worng; that's not actually the one that's used in production.
Upvotes: 1