You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AngularDart 5(alpha)测试命令执行异常问题求助

Hey there, let's sort out this testing headache with AngularDart 5 alpha—those outdated docs can be a real pain, right? Let's break down why you're seeing those two issues and how to fix them.

First: Why "No tests ran"?

Most likely, build_runner can't find your test files, or they don't follow the expected naming/convention rules:

  • Your test files need to live in the test/ directory (or a subfolder under it) and end with _test.dart (like app_component_test.dart). Build_runner uses this pattern to auto-discover tests by default.
  • Double-check that you've imported the necessary Angular testing libraries in your test files (like package:angular_test/angular_test.dart)—without that, even if the file is found, it might not register any test cases.

Second: Why the "dart:html not available" crash?

AngularDart component tests rely on browser APIs (hence dart:html), but the default pub run build_runner test command runs tests in a VM environment (which doesn't have browser APIs). You need to explicitly tell it to use a browser platform.

The Fix: Correct Test Command & Setup

Here's what you need to do step by step:

  1. Verify your dev dependencies in pubspec.yaml (make sure they're compatible with AngularDart 5 alpha):

    dev_dependencies:
      angular_test: ^5.0.0-alpha
      build_test: ^2.1.0
      test: ^1.24.0
    

    Run pub get to ensure these are installed.

  2. Use the right build_runner command that targets a browser:

    # Run all tests in headless Chrome (great for CI)
    pub run build_runner test --platform chrome --headless
    
    # Or run tests in a visible Chrome window
    pub run build_runner test --platform chrome
    
    # Run a single test file if you don't want to run everything
    pub run build_runner test --platform chrome test/app_component_test.dart
    
  3. Optional: Customize test discovery (if needed)
    If your tests are in non-standard paths, create a build.yaml file in your project root to tell build_runner where to look:

    targets:
      $default:
        builders:
          build_test:test_config:
            generate_for:
              - test/**/*_test.dart
              # Add any other paths here if your tests are elsewhere
    

Quick Recap

The core issue was that you weren't specifying the browser platform—without that, build_runner tries to run Angular tests in a VM which can't handle dart:html. And the "No tests ran" problem was either missing the right file naming/convention or incorrect dependencies.

Give these steps a shot, and you should have your AngularDart 5 alpha tests running smoothly!

内容的提问来源于stack exchange,提问作者Rémi Rousselet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:57:59