久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Angular 中使用 Jasmine 使用 *ngIf 指令時,如何對

How do I unit test if an element is visible when the *ngIf directive is used using Jasmine in Angular(在 Angular 中使用 Jasmine 使用 *ngIf 指令時,如何對元素是否可見進行單元測試) - IT屋-程序員軟件開發技術分享
本文介紹了在 Angular 中使用 Jasmine 使用 *ngIf 指令時,如何對元素是否可見進行單元測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個 Angular 6 應用程序并編寫了一些單元測試,試圖僅根據 *ngIf 指令的布爾結果來確定元素是否可見.

I have an Angular 6 app and writing some unit tests trying to determine if an element is visible or not based solely on the boolean result of an *ngIf directive.

標記:

<div class="header" *ngIf="show">
    <div>...</div>
</div>

規格文件:

it('should hide contents if show is false', () => {
    const button = debugElement.query(By.css('button')).nativeElement;
    button.click();   // this will change show to false
    fixture.detectChanges();
    expect(debugElement.query(By.css('.header')).nativeElement.style.hidden).toBe(true);
});

我似乎無法從 div 中獲取 hidden 屬性.Angular 是否使用另一種方法使用 *ngIf 指令從 DOM 中隱藏元素?我需要從 nativeElement 獲取另一個屬性嗎?

I can't seem to get the hidden attribute from the div. Does angular use another approach to hiding the element from the DOM using the *ngIf directive? Do I need to get another property from the nativeElement?

謝謝!

推薦答案

如果元素被隱藏,則不會在dom中渲染.

If the element is hidden, then it wont be rendered inside the dom.

你可以檢查

expect(fixture.debugElement.query(By.css('.header'))).toBeUndefined();

EDIT : toBeNull() 在上述情況下效果更好

EDIT : toBeNull() works better in the above case

expect(fixture.debugElement.query(By.css('.header'))).toBeNull();

您在獲取按鈕元素時也遇到了語法錯誤.nativeElement 不是函數.

And also you have a syntax error while fetching the button element. nativeElement is not a function.

這樣改:

const button = fixture.debugElement.query(By.css('button')).nativeElement;

這篇關于在 Angular 中使用 Jasmine 使用 *ngIf 指令時,如何對元素是否可見進行單元測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 久久久精品视 | 日韩精品免费在线观看 | av一级在线观看 | 成人午夜激情 | 一区二区三区四区在线 | 亚洲精品一区国语对白 | 色综合视频 | 狠狠爱一区二区三区 | 中文字幕乱码一区二区三区 | 在线成人 | 一区二区精品 | 亚洲精品日韩综合观看成人91 | 一区二区三区福利视频 | 成人在线一区二区三区 | 精品国产一区二区在线 | 天天澡天天狠天天天做 | 美国十次成人欧美色导视频 | 丁香六月伊人 | 国产电影一区二区三区爱妃记 | 精品乱码一区二区三四区视频 | 亚洲综合伊人 | 2018中文字幕第一页 | 天天操天天天 | 一区二区三区视频在线免费观看 | 国产精品国产三级国产aⅴ中文 | 精品国产乱码久久久久久丨区2区 | 99精品久久 | 久久精品天堂 | 午夜精品一区 | 成人在线精品 | 精品av| a级片播放 | 日韩精品中文字幕一区二区三区 | 99久久精品免费看国产免费软件 | 婷婷精品| 在线成人| 久久毛片 | 国产一区二区精品自拍 | 国产在线观看不卡一区二区三区 | 婷婷中文在线 | 色频|