В css
я мог бы сделать a[href^="https"]
, который выбирает каждый элемент <a>
, значение атрибута которого href
начинается с "https".Как я могу указать то же правило в By.css
в Angular
?
By.css
определяется в https://angular.io/api/platform-browser/By как
static css(selector: string): Predicate<DebugElement>
MyКод Angular
имеет несколько div
с атрибутом id
, равным thumbnail-1
, thumbnail-2
.Я хочу получить их все в моем Jasmine
модульном тесте.
В данный момент я собираю их по отдельности
let imageThumbnailDiv1 = fixture.debugElement.query(By.css("#thumbnail-1"));
let imageThumbnailDiv2 = fixture.debugElement.query(By.css("#thumbnail-2"));
Если яиспользовать шаблон множественного выбора, я получаю только 1-й элемент.Есть ли способ получить несколько элементов.
fit('select all thumbnails',(done)=>{
let newPracticeQuestionComponent = component;
let imageThumbnailDivs = fixture.debugElement.query(By.css("div[id^=\"thumbnail\"]"));
console.log("thumbnail divs before file upload ",imageThumbnailDivs);
expect(imageThumbnailDivs).toBeFalsy();
let file1 = new File(["foo1"], "foo1.txt");
let file2 = new File(["foo2"], "foo2.txt");
let file3 = new File(["foo3"], "foo3.txt");
//let file4 = new File(["foo4"], "foo4.txt");
let reader1 = newPracticeQuestionComponent.handleFileSelect([file1]);
let reader2 = newPracticeQuestionComponent.handleFileSelect([file2]);
let reader3 = newPracticeQuestionComponent.handleFileSelect([file3]);
setTimeout(function() {
console.log("in timeout");
fixture.detectChanges();//without this, the view will not be updated with model
let imageThumbnailDivsAfter = fixture.debugElement.query(By.css("div[id^=\"thumbnail\""));
console.log("thumbnail divs after file upload ",imageThumbnailDivsAfter); //<-- this shows only the 1st element
expect(imageThumbnailDivsAfter).toBeTruthy();
//console.log("before done call")
done();//without done, jasmine will finish this test spec without checking the assertions in the timeout
//console.log("after timeout call")
}, 2000);
});