简体   繁体   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

When running the tests on my project when trying to render the component, the tests fail with the following error:在尝试渲染组件时在我的项目上运行测试时,测试失败并出现以下错误:

TypeError: testing.TestBed.inject is not a function

This is the test component:这是测试组件:

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
    }
  }

This is the test with testing library for Angular:这是针对 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();
  })
})

What version of @testing-library/angular are you on?您使用的是哪个版本的 @testing-library/angular? I think the version isn't compatible with Angular v6.我认为该版本与 Angular v6 不兼容。 Try upgrading/downgrading testing library.尝试升级/降级测试库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决错误 TypeError: x is not a function for testing the following function in Jest? - How to resolve the error TypeError: x is not a function for testing of the following function in Jest? 玩笑测试:TypeError: (0 , _rtb.disableAllAds) is not a function - Jest testing: TypeError: (0 , _rtb.disableAllAds) is not a function 玩笑错误 TypeError: (0 , _jest.test) is not a function - Jest error TypeError: (0 , _jest.test) is not a function 如何修复 TypeError 不是函数(用 Jest 测试 promise) - How to fix TypeError is not a function (testing promises with Jest) 开玩笑-测试mobx存储@action TypeError:不是函数 - jest - testing mobx store @action TypeError: is not a function 测试 Function 在 Jest 中抛出错误 - Testing Function to Throw an Error in Jest 使用Jest在线测试Firestore时出错:“验证错误:TypeError:fetch不是函数” - Error when testing Firestore online with Jest: “Auth error:TypeError: fetch is not a function” TypeError:firebase.initializeApp不是仅当玩笑运行测试时的函数 - TypeError: firebase.initializeApp is not a function only when jest runs tests 没有@Inject,Angular2 TestBed找不到嵌套的提供者 - Angular2 TestBed can't find nested provider without @Inject AngularJS中的测试:注入函数的参考错误 - Tests in AngularJS: Reference error of the inject function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM