簡體   English   中英

Angular 6 和 Jest 的測試出錯 - TypeError: testing.TestBed.inject is not a function

[英]Error in tests with Angular 6 and Jest - TypeError: testing.TestBed.inject is not a function

在嘗試渲染組件時在我的項目上運行測試時,測試失敗並出現以下錯誤:

TypeError: testing.TestBed.inject is not a function

這是測試組件:

import { Component, Input } from "@angular/core";
@Component({
    selector: 'counter',
    template: `
      <button (click)="decrement()">-</button>
      <span data-testid="count">Current Count: {{ counter }}</span>
      <button (click)="increment()">+</button>
    `,
  })
  export class CounterComponent {
    @Input() counter = 0
  
    increment() {
      this.counter += 1
    }
  
    decrement() {
      this.counter -= 1
    }
  }

這是針對 Angular 的測試庫的測試:

import {render, screen } from '@testing-library/angular'
import {CounterComponent} from './prueba.component'

describe('Counter', () => {
  test('should render counter', async () => {
    await render(CounterComponent, {
      componentProperties: {counter: 5},
    })
    expect(screen.getByText('Current Count: 5')).toBeTruthy();
  })
})

您使用的是哪個版本的 @testing-library/angular? 我認為該版本與 Angular v6 不兼容。 嘗試升級/降級測試庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM