|
1 | | -import { querySelectorAllDeep, querySelectorDeep } from '../src/querySelectorDeep.js'; |
| 1 | +import { querySelectorAllDeep, querySelectorDeep, collectAllElementsDeep } from '../src/querySelectorDeep.js'; |
2 | 2 | import { createTestComponent, createNestedComponent, COMPONENT_NAME, createChildElements } from './createTestComponent.js'; |
3 | 3 |
|
4 | 4 |
|
@@ -33,6 +33,10 @@ describe("Basic Suite", function() { |
33 | 33 | expect(querySelectorDeep).toEqual(jasmine.any(Function)); |
34 | 34 | }); |
35 | 35 |
|
| 36 | + it("exports collectAllElementsDeep function", function() { |
| 37 | + expect(collectAllElementsDeep).toEqual(jasmine.any(Function)); |
| 38 | + }); |
| 39 | + |
36 | 40 | it("querySelectorDeep returns null when not found", function() { |
37 | 41 | expect(querySelectorDeep('whatever')).toBeNull(); |
38 | 42 | }); |
@@ -324,6 +328,35 @@ describe("Basic Suite", function() { |
324 | 328 |
|
325 | 329 | }); |
326 | 330 |
|
| 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 | + |
327 | 360 | it('can query nodes in an iframe', function(done) { |
328 | 361 |
|
329 | 362 | const innerframe = `<p class='child'>Content</p>`; |
|
0 commit comments