पाठ 29 / 30
कंपोनेंट टेस्ट करना
TestBed किसी कंपोनेंट को टेस्ट करने के लिए एक अलग वातावरण तैयार करता है।
TestBed क्या करता है
TestBed, टेस्ट के लिए एक छोटा Angular मॉड्यूल बनाता है, जिससे आप असली या नकली निर्भरताओं के साथ कंपोनेंट बना सकते हैं और उसका रेंडर हुआ आउटपुट जाँच सकते हैं।
एक न्यूनतम टेस्ट
यह टेस्ट कंपोनेंट बनाता है, चेंज डिटेक्शन ट्रिगर करता है, और इंस्टेंस पर एक मान जाँचता है।
describe('CounterComponent', () => {
it('increments the count', () => {
const fixture = TestBed.createComponent(CounterComponent);
const component = fixture.componentInstance;
component.increment();
fixture.detectChanges();
expect(component.count()).toBe(1);
});
});