最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sapui5 - Loading a component's file in test context of a different component - Stack Overflow

programmeradmin1浏览0评论

I have a SAPUI5 app with 5 components in total: 4 components and 1 shared component which contains the shared files.
All of them are under the root folder.
The first component's code uses a file from the shared component, when I test it in the UI everything works fine without any issue.
When I run the tests, the problems start, and it's failing from the first test.
After a long debug session and spending a lot of hours on it, I figured out that the files coming from the shared component are not loaded in the component1's test context.
Following is the manifest.js file (only the part where I load the shared component) from Component1:

"sap.ui5": {
    "resourceRoots": {
      "sharedponent": "../shared-component/"
    }
}

I updated as well the file opaTests.qunit.html as following:

data-sap-ui-resourceroots='{
            "component1": "./../../",
            "sharedponent": "./../../../shared-component"
        }'

I added as well a script to the file opaTests.qunit.html to explicitly load the shared file:

<script>
    sap.ui.require.preload({
      "path/to/shared/component/MessageBox.js": `
        sap.ui.define([], function () {
          "use strict";

          return {
            showWarningAsync: async function (sText, primaryAction, secondaryAction, sTitle) {
              return new Promise((resolve) => {
                console.log(\`Mock MessageBox.warning called with:
                  Text: \${sText}
                  Title: \${sTitle}
                  Primary Action: \${primaryAction}
                  Secondary Action: \${secondaryAction}\`);

                const oAction = primaryAction;
                resolve(oAction === primaryAction);
              });
            }
          };
        });
      `
    });
</script>

I can't find any related example neither here nor in SAPUI5 documentation.

I have a SAPUI5 app with 5 components in total: 4 components and 1 shared component which contains the shared files.
All of them are under the root folder.
The first component's code uses a file from the shared component, when I test it in the UI everything works fine without any issue.
When I run the tests, the problems start, and it's failing from the first test.
After a long debug session and spending a lot of hours on it, I figured out that the files coming from the shared component are not loaded in the component1's test context.
Following is the manifest.js file (only the part where I load the shared component) from Component1:

"sap.ui5": {
    "resourceRoots": {
      "sharedponent": "../shared-component/"
    }
}

I updated as well the file opaTests.qunit.html as following:

data-sap-ui-resourceroots='{
            "component1": "./../../",
            "sharedponent": "./../../../shared-component"
        }'

I added as well a script to the file opaTests.qunit.html to explicitly load the shared file:

<script>
    sap.ui.require.preload({
      "path/to/shared/component/MessageBox.js": `
        sap.ui.define([], function () {
          "use strict";

          return {
            showWarningAsync: async function (sText, primaryAction, secondaryAction, sTitle) {
              return new Promise((resolve) => {
                console.log(\`Mock MessageBox.warning called with:
                  Text: \${sText}
                  Title: \${sTitle}
                  Primary Action: \${primaryAction}
                  Secondary Action: \${secondaryAction}\`);

                const oAction = primaryAction;
                resolve(oAction === primaryAction);
              });
            }
          };
        });
      `
    });
</script>

I can't find any related example neither here nor in SAPUI5 documentation.

Share Improve this question asked Feb 2 at 9:19 GothiquoGothiquo 8681 gold badge11 silver badges33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

1.for file opaTests.qunit.html point to ./resources

data-sap-ui-resourceroots='{
            "sharedponent": "./resources/shared-component"
        }'

2.host shared component under ./resources path for the test site.

    - name: ui5-middleware-servestatic
      afterMiddleware: compression
      mountPath: /resources
      configuration:
        rootPath: "./shared-component"
发布评论

评论列表(0)

  1. 暂无评论