[英]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.