不完整的 Angular Karma Jasmine 规格不再在 fit/fdescribe 上失败

问题描述 投票:0回答:1

我的构建系统没有拒绝最近通过集中测试提交的 PR

fdescribe
。过去,当使用 fdescribe()/
fit()
测试运行时,
jasmine
将返回非零退出代码。最近(?)然而,这似乎已经停止工作了。

由于我可以在新的 Angular 项目中重现,我猜测这不是我的设置问题。但我猜这可能是 NodeJS v20.10 问题,或者 MacOS 问题。

关于如何使其再次正常工作有什么建议吗?

示例输出:

创建一个新应用程序:

npx -p @angular/cli ng new --strict --standalone --routing --style=scss demo-v17

将默认测试之一标记为

fit

~/.../demo-v17 (main *)$ ng test --no-watch
✔ Browser application bundle generation complete.
12 12 2023 09:49:33.067:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9877/
12 12 2023 09:49:33.069:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
12 12 2023 09:49:33.072:INFO [launcher]: Starting browser Chrome
12 12 2023 09:49:34.328:INFO [Chrome 120.0.0.0 (Mac OS 10.15.7)]: Connected on socket bTNnn02qMyLlZwf8AAAB with id 66356302
Chrome 120.0.0.0 (Mac OS 10.15.7): Executed 1 of 3 (skipped 2) SUCCESS (0.066 secs / 0.058 secs)
Chrome 120.0.0.0 (Mac OS 10.15.7) ERROR
  Some of your tests did a full page reload!
Chrome 120.0.0.0 (Mac OS 10.15.7): Executed 1 of 3 (skipped 2) ERROR (0.066 secs / 0.058 secs)
Chrome 120.0.0.0 (Mac OS 10.15.7) ERROR
Chrome 120.0.0.0 (Mac OS 10.15.7): Executed 1 of 3 (skipped 2) ERROR (0.076 secs / 0.058 secs)
~/.../demo-v17 (main *)$ echo $?
0

奇怪的是“错误,您的一些测试进行了整页重新加载!”也没有导致错误的退出代码。但这就是默认的 Angular v17 的做法,所以我认为它不是其中的一部分。

$ ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 17.0.6
Node: 20.10.0
Package Manager: npm 10.2.3
OS: darwin x64

Angular: 17.0.6
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.6
@angular-devkit/build-angular   17.0.6
@angular-devkit/core            17.0.6
@angular-devkit/schematics      17.0.6
@schematics/angular             17.0.6
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2 
angular jasmine karma-jasmine
1个回答
0
投票

对于

"ERROR Some of your tests did a full page reload!"
没有通过测试,我不确定这个问题。

为了使

fit/fdescribe
上的管道失败,我使用 ESlint 插件来帮助解决此问题。如果您的项目中有 linting,这可能是解决失败问题的好方法
fit/fdescribe

这是我的 eslint 配置的一部分

.spec.ts
文件:

{
      files: ['src/**/*.spec.ts'],
      parser: '@typescript-eslint/parser',
      parserOptions: {
        project: ['tsconfig.spec.json'],
        createDefaultProgram: true
      },
      plugins: ['jasmine'],
      env: {
        jasmine: true,
        browser: true
      },
      extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:jasmine/recommended',
        'prettier'
      ],
      rules: {
        'import/order': [
          'error',
          {
            groups: [
              'builtin',
              'external',
              'parent',
              'sibling',
              'index'
            ],
            'newlines-between': 'always',
            alphabetize: {
              order: 'asc'
            }
          }
        ],
        'jasmine/no-spec-dupes': [2, 'branch'],
        'jasmine/no-suite-dupes': [2, 'branch'],
        'jasmine/prefer-toHaveBeenCalledWith': [0],
        'jasmine/new-line-before-expect': [0],
        '@typescript-eslint/no-explicit-any': 'off',
        '@typescript-eslint/no-empty-function': 'off',
        'no-console': 'error'
      }
    },

该插件是

eslint-plugin-jasmine
https://www.npmjs.com/package/eslint-plugin-jasmine)。

规则是

no-focused-tests

如果运行

npm run lint
,lint 将会失败。您还可以将 linting 引入 HTML 和 TypeScript 文件。如果您没有 linting,您可以研究如何将 linting 引入 Angular,然后在此基础上将 linting 引入单元测试文件。

© www.soinside.com 2019 - 2024. All rights reserved.