【问题标题】:Angular unit testing: How to serve css files now in karma with angular 6+Angular 单元测试:如何使用 Angular 6+ 在业力中提供 css 文件
【发布时间】:2019-02-10 07:41:39
【问题描述】:

我想在我的规范中加入材质 css。在我在 karma config 中使用它之前:

files: [
   // make sure material styles are served
   { pattern: './node_modules/@angular/material/prebuilt-themes/indigo-pink.css', watched: true, included: true, served: true },

   { pattern: './src/test.ts', watched: false }
]

但新项目在 karma 配置中不再具有 files 属性。

我尝试在 angular.json 中添加它,但它不起作用:

"test": {
      ...
      "options": {
        "main": "src/test.ts",
        ...
        "karmaConfig": "src/karma.conf.js",
        "styles": [
          "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
          "src/styles.scss"
        ],

知道现在该怎么做吗?

【问题讨论】:

    标签: angular angular-cli karma-jasmine angular-cli-v6


    【解决方案1】:

    没关系,路径错了?这行得通(业力配置):

    files: [
      // make sure angular material styles are served
      { pattern: '../node_modules/@angular/material/prebuilt-themes/indigo-pink.css', watched: true, included: true, served: true },
    ]
    

    【讨论】:

      【解决方案2】:

      我的文件在 url 的完整路径之外提供。 http://localhost:9876/Users/david/myapp/src/test/data/pages/table.html

      解决方案是在 url 中使用单词“base”访问您的文件

      http://localhost:9876/base/test/data/pages/table.html

        files: [{pattern: 'test/data/pages/**.html', watched: true, served: true, included: false, nocache: true}]
      

      【讨论】:

        猜你喜欢
        • 2019-04-16
        • 1970-01-01
        • 2014-01-21
        • 1970-01-01
        • 2018-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-10
        相关资源
        最近更新 更多