Skip to content

Make the virtual console behave correctly with errors

What does this MR do and why?

Internally, the virtual console throws an error if the argument passed is not an string.

Now, we check if the argument is a string before using string methods, like includes. Otherwise, we assume they are Errors.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Create a file like this one:
diff --git a/spec/frontend/test_spec.js b/spec/frontend/test_spec.js
new file mode 100644
index 000000000000..857652c3c0cb
--- /dev/null
+++ b/spec/frontend/test_spec.js
@@ -0,0 +1,4 @@
+it('throws method not implemented', () => {
+  window.open('https://example.com');
+  expect(1).toEqual(1);
+});
  1. Run yarn jest spec/frontend/test_spec.js

Before

  ● throws method not implemented

    TypeError: _args$.includes is not a function

      41 |         }
      42 |         throw new ErrorWithStack(
    > 43 |           `Unexpected call of console.warn() with:\n\n${args.join(', ')}`,
         |                                                                                               ^
      44 |           this.warn,
      45 |         );
      46 |       },

      at console.error (spec/frontend/environment.js:43:108)
      at module.exports (node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26)
      at node_modules/jsdom/lib/jsdom/browser/Window.js:864:7
      at Object.open (spec/frontend/test_spec.js:2:10)

After

  ● throws method not implemented

    Unexpected call of console.error() with:

    Error: Not implemented: window.open

      1 | it('throws method not implemented', () => {
    > 2 |   window.open('https://example.com');
        |          ^
      3 |   expect(1).toEqual(1);
      4 | });
      5 |

      at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/build/index.js:70:23)
      at module.exports (node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26)
      at node_modules/jsdom/lib/jsdom/browser/Window.js:864:7
      at Object.open (spec/frontend/test_spec.js:2:10)
Edited by Eduardo Sanz García

Merge request reports

Loading