Skip to content

Commit f242b08

Browse files
committed
add test for "collectAllElementsDeep"
1 parent 59b2b9c commit f242b08

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/basic.spec.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { querySelectorAllDeep, querySelectorDeep } from '../src/querySelectorDeep.js';
1+
import { querySelectorAllDeep, querySelectorDeep, collectAllElementsDeep } from '../src/querySelectorDeep.js';
22
import { createTestComponent, createNestedComponent, COMPONENT_NAME, createChildElements } from './createTestComponent.js';
33

44

@@ -33,6 +33,10 @@ describe("Basic Suite", function() {
3333
expect(querySelectorDeep).toEqual(jasmine.any(Function));
3434
});
3535

36+
it("exports collectAllElementsDeep function", function() {
37+
expect(collectAllElementsDeep).toEqual(jasmine.any(Function));
38+
});
39+
3640
it("querySelectorDeep returns null when not found", function() {
3741
expect(querySelectorDeep('whatever')).toBeNull();
3842
});
@@ -324,6 +328,35 @@ describe("Basic Suite", function() {
324328

325329
});
326330

331+
it('can cache collected elements with collectAllElementsDeep', function() {
332+
const root = document.createElement('div');
333+
parent.appendChild(root);
334+
335+
createTestComponent(root, {
336+
childClassName: 'inner-content'
337+
});
338+
339+
createTestComponent(parent, {
340+
childClassName: 'inner-content'
341+
});
342+
const collectedElements = collectAllElementsDeep('', root)
343+
expect(collectedElements.length).toEqual(4);
344+
345+
const testComponents = querySelectorAllDeep('.inner-content', root, collectedElements);
346+
expect(testComponents.length).toEqual(1);
347+
348+
// remove element from dom
349+
testComponents[0].remove()
350+
351+
// not found in dom
352+
const testComponents2 = querySelectorAllDeep('.inner-content', root);
353+
expect(testComponents2.length).toEqual(0);
354+
355+
// still there with cached collectedElements
356+
const testComponents3 = querySelectorAllDeep('.inner-content', root, collectedElements);
357+
expect(testComponents3.length).toEqual(1);
358+
});
359+
327360
it('can query nodes in an iframe', function(done) {
328361

329362
const innerframe = `<p class='child'>Content</p>`;

0 commit comments

Comments
 (0)