Theia Test failing in v1.25.0

Hi ,

I have updated my theia version from v1.20.0 to v1.25.0.

I have a view which injects OutputChannelManager . When I ran my tests I am getting the error below, any idea, about this issue, as I couldn’t find if this is related to react-testing library or theia api

Test suite failed to run
test-extension:     TypeError: document.queryCommandSupported is not a function
test-extension:       46 | import {FrontendApplicationContribution} from '@theia/core/lib/browser';
test-extension:       47 | import {inject, injectable, interfaces} from '@theia/core/shared/inversify';
test-extension:     > 48 | import {OutputChannelManager, OutputChannelSeverity} from     '@theia/output/lib/browser/output-channel';
test-extension:          | ^
test-extension:       49 | const CHANNEL_NAME = 'Test Channel';
test-extension:       50 | @injectable()
test-extension:       51 | export class TestOutputChannel implements FrontendApplicationContribution {
test-extension:       at Object.<anonymous> (../../node_modules/@theia/monaco-editor-core/src/vs/editor/contrib/clipboard/browser/clipboard.ts:24:52)
test-extension:       at Object.<anonymous> (../../node_modules/@theia/monaco-editor-core/src/vs/editor/editor.all.ts:14:1)
test-extension:       at Object.<anonymous> (../../node_modules/@theia/monaco-editor-core/src/vs/editor/editor.main.ts:6:1)
test-extension:       at Object.<anonymous> (../../node_modules/@theia/monaco/src/browser/monaco-editor-model.ts:29:1)
test-extension:       at Object.<anonymous> (../../node_modules/@theia/monaco/src/browser/monaco-text-model-service.ts:21:1)
test-extension:       at Object.<anonymous> (../../node_modules/@theia/output/src/browser/output-channel.ts:24:1)

The document.queryCommandSupported browser API has been deprecated for some time. I assume that your dom-testing library has dropped support for it completely, which now leads to an error.

This is kind of unrelated to Theia, but I guess as a workaround you can just create a stub for it like this:

document.queryCommandSupported = () => false;
2 Likes

I tried the solution in theia repo. tab-bars-spec.ts / bulk-edit-tree-spec.ts

add this on top of my class imports

import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
let disableJSDOM = enableJSDOM();
disableJSDOM();


before(() => {

            disableJSDOM = enableJSDOM();

            });

    after(() => {

        disableJSDOM();

    });

But the problem remains as it is.

I have found a solution. as suggested by @msujew , I have added a mock file and added it to the imports at the top.

global.document.queryCommandSupported = () => ({    
    });