SkillByAIइंटरैक्टिव संस्करण खोलें →

पाठ 30 / 32

कंपोनेंट टेस्ट करना

TestBed, change detection और component state पर assertions के साथ components को अलग से test करें।

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