Skip to content

Commit a057050

Browse files
feanilclaude
andcommitted
fix: reset MathJax.Hub.Queue spy in refreshMath beforeEach to avoid jasmine-jquery Sizzle error
In Jasmine 2.99, toHaveBeenCalledWith iterates ALL recorded spy call arguments element-by-element (even for calls that obviously don't match) to build a useful diff. In Jasmine 2.6, array comparison short-circuited on the first failing element. Problem.bind() calls MathJax.Hub.Queue([refreshMath, null, domEl]) for each input.math element. When toHaveBeenCalledWith then checks that call against the expected args ["Text", stubbedJax, "E=mc^2"], it compares each element pairwise — including domEl (index 2 of the actual array) against "E=mc^2" (index 2 of the expected array). jasmine-jquery's custom equality tester calls $(domEl).is("E=mc^2") when it sees a DOM node on the left. jQuery's Sizzle interprets "E=mc^2" as a CSS selector and throws a syntax error. Fix: reset Queue.calls after new Problem() so bind()'s call is not in the recorded set. This isolates the describe to testing only what refreshMath itself queues, which is the intent of the test. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 46e0b76 commit a057050

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

xmodule/js/spec/capa/display_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,15 @@ data-url='/problem/quiz/'> \
994994
describe("refreshMath", function () {
995995
beforeEach(function () {
996996
this.problem = new Problem($(".xblock-student_view"));
997+
// Reset Queue spy so that bind()'s Queue call ([fn, null, domEl]) is not
998+
// included when toHaveBeenCalledWith scans recorded calls. In Jasmine 2.99,
999+
// toHaveBeenCalledWith iterates ALL recorded calls' args element-by-element
1000+
// (even mismatched ones, for diff output). jasmine-jquery's custom equality
1001+
// tester calls $(domEl).is(anyString) when comparing a DOM node against a
1002+
// string — which throws a Sizzle syntax error if the string isn't a valid
1003+
// CSS selector (e.g. "E=mc^2"). Resetting here isolates this describe to
1004+
// testing only what refreshMath itself queues.
1005+
MathJax.Hub.Queue.calls.reset();
9971006
$("#input_example_1").val("E=mc^2");
9981007
this.problem.refreshMath({ target: $("#input_example_1").get(0) });
9991008
});

0 commit comments

Comments
 (0)