[英]Angular: How to test RadioButton?
Angular Material 提供了 MatButtonHarness 來測試常規的 HTML 按鈕。 有了它,您可以“獲取文本”、“點擊”。
有沒有類似於測試 RadioButtons 的東西? 我希望 MatRadioHarness 存在,但事實並非如此。
如果沒有,推薦的方法是什么?
謝謝!
我找不到任何文檔,但查看“MatButtonHarness”的源代碼在哪里(~myproject\\node_modules@angular\\material\\button)我能夠使用單選按鈕的線束類(c:\\Project\\AngularLearning\\前端\\node_modules@angular\\material\\radio)。
在“testing”子文件夾中,我能夠找到與 Radio Button Harness 一起使用的實際類:MatRadioGroupHarness 和 MatRadioButtonHarness。 顯而易見的答案,但令人困惑的是單選按鈕的類中沒有“按鈕”。
在我找到特定的類后,我搜索了這些類並確定了工作示例: https ://stackblitz.com/angular/rllllvapblod?file=src%2Fapp%2Fradio-harness-example.spec.ts
使其工作的一個重要部分是將 MatRadioModule 添加到我的測試初始化的導入部分:
describe('MapsComponent', () => {
let component: MapsComponent;
let fixture: ComponentFixture<MapsComponent>;
let componentService: HexesService;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatRadioModule],
declarations: [MapsComponent],
}).compileComponents();
...
希望這也能幫助別人!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.