Thuta Learning
ရှာဖွေရန်
AdvancedWeb Developmentintermediate

Testing Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Angular သည် Jasmine နှင့် Karma ဖြင့် unit testing များကို support လုပ်သည်။

typescript
// app.component.spec.ts
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [AppComponent]
    }).compileComponents();
  });
  
  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });
  
  it('should have title "my-app"', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app.title).toEqual('my-app');
  });
  
  it('should render title', () => {
    const fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    const compiled = fixture.nativeElement;
    expect(compiled.querySelector('h1').textContent)
      .toContain('my-app');
  });
});

// Run tests: ng test
You should see
(Tests များ run လုပ်လျှင် component ၏ behavior ကို verify လုပ်ပြီး pass/fail results ပြသမည်)
Testing Basics | Thuta Learning