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:
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? I think the version isn't compatible with Angular v6. Try upgrading/downgrading testing library.