|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
| 5 | +/* global jest */ |
5 | 6 | const { shallow } = require("enzyme"); |
6 | 7 | const { |
7 | 8 | REPS, |
@@ -332,3 +333,80 @@ describe("Error - base-loader.js", () => { |
332 | 333 | expect(renderedComponent).toMatchSnapshot(); |
333 | 334 | }); |
334 | 335 | }); |
| 336 | + |
| 337 | +describe("Error - stacktrace location click", () => { |
| 338 | + it("Calls onViewSourceInDebugger with the expected arguments", () => { |
| 339 | + const onViewSourceInDebugger = jest.fn(); |
| 340 | + const object = stubs.get("base-loader Error"); |
| 341 | + |
| 342 | + const renderedComponent = shallow(ErrorRep.rep({ |
| 343 | + object, |
| 344 | + onViewSourceInDebugger |
| 345 | + })); |
| 346 | + |
| 347 | + const locations = renderedComponent.find(".objectBox-stackTrace-location"); |
| 348 | + expect(locations.exists()).toBeTruthy(); |
| 349 | + |
| 350 | + expect(locations.first().prop("title")).toBe("View source in debugger"); |
| 351 | + locations.first().simulate("click", { |
| 352 | + type: "click", |
| 353 | + stopPropagation: () => {}, |
| 354 | + }); |
| 355 | + |
| 356 | + expect(onViewSourceInDebugger.mock.calls.length).toEqual(1); |
| 357 | + let mockCall = onViewSourceInDebugger.mock.calls[0][0]; |
| 358 | + expect(mockCall.url).toEqual("resource://devtools/shared/client/debugger-client.js"); |
| 359 | + expect(mockCall.line).toEqual(856); |
| 360 | + expect(mockCall.column).toEqual(9); |
| 361 | + |
| 362 | + expect(locations.last().prop("title")).toBe("View source in debugger"); |
| 363 | + locations.last().simulate("click", { |
| 364 | + type: "click", |
| 365 | + stopPropagation: () => {}, |
| 366 | + }); |
| 367 | + |
| 368 | + expect(onViewSourceInDebugger.mock.calls.length).toEqual(2); |
| 369 | + mockCall = onViewSourceInDebugger.mock.calls[1][0]; |
| 370 | + expect(mockCall.url).toEqual("resource://devtools/shared/ThreadSafeDevToolsUtils.js"); |
| 371 | + expect(mockCall.line).toEqual(109); |
| 372 | + expect(mockCall.column).toEqual(14); |
| 373 | + }); |
| 374 | + |
| 375 | + it("Does not call onViewSourceInDebugger on excluded urls", () => { |
| 376 | + const onViewSourceInDebugger = jest.fn(); |
| 377 | + const object = stubs.get("URIError"); |
| 378 | + |
| 379 | + const renderedComponent = shallow(ErrorRep.rep({ |
| 380 | + object, |
| 381 | + onViewSourceInDebugger |
| 382 | + })); |
| 383 | + |
| 384 | + const locations = renderedComponent.find(".objectBox-stackTrace-location"); |
| 385 | + expect(locations.exists()).toBeTruthy(); |
| 386 | + expect(locations.first().prop("title")).toBe(undefined); |
| 387 | + |
| 388 | + locations.first().simulate("click", { |
| 389 | + type: "click", |
| 390 | + stopPropagation: () => {}, |
| 391 | + }); |
| 392 | + |
| 393 | + expect(onViewSourceInDebugger.mock.calls.length).toEqual(0); |
| 394 | + }); |
| 395 | + |
| 396 | + it("Does not throw when onViewSourceInDebugger props is not provided", () => { |
| 397 | + const object = stubs.get("base-loader Error"); |
| 398 | + |
| 399 | + const renderedComponent = shallow(ErrorRep.rep({ |
| 400 | + object, |
| 401 | + })); |
| 402 | + |
| 403 | + const locations = renderedComponent.find(".objectBox-stackTrace-location"); |
| 404 | + expect(locations.exists()).toBeTruthy(); |
| 405 | + expect(locations.first().prop("title")).toBe(undefined); |
| 406 | + |
| 407 | + locations.first().simulate("click", { |
| 408 | + type: "click", |
| 409 | + stopPropagation: () => {}, |
| 410 | + }); |
| 411 | + }); |
| 412 | +}); |
0 commit comments