微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Karma 中排除编译样式? - 角度测试

如何解决如何在 Karma 中排除编译样式? - 角度测试

我正在尝试使用 Karma 在我的 Angular 应用程序中运行前端单元测试。但是我无法编译测试,在控制台中运行“ng test”时它失败并显示以下错误消息:

Error: Module build Failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
  ╷
1 │ @use 'internal-library' as *;
  │ ^^^^^^^^^^^^^^^^^^^^^^
  ╵
  ../../../src/styles/global.scss 1:1  @import
  ../../../src/styles/styles.scss 8:9  root stylesheet

如何从 karma 中排除编译样式表?或者我应该尝试其他解决方案吗?

回复:第一条评论,我按照其他答案的建议更新了我的 angular.json,如下:

"styles": [
              "src/styles/styles.scss"
            ],"stylePreprocessorOptions": {
              "includePaths": [
                "src/styles"
              ]
            },

(适应我的文件结构)

-src
  -styles
      -global.scss -> here's the import it's struggling with
      -styles.scss -> the global file is then imported here
    -api
      -mixins.scss
      -variables.scss

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。