Last active
September 11, 2022 21:08
-
-
Save jimkeller/684410c9e65c602f7a65c777a58fbfab to your computer and use it in GitHub Desktop.
Sample Jest test for raw HTML Markup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, expect, test, beforeEach } from '@jest/globals' | |
import { Renderer } from '../Renderer' | |
import { nested_html } from "../../test/fixtures/nested_html" | |
describe('Nested HTML Parser', () => { | |
let container: HTMLElement | |
let test_element: HTMLElement | |
let children: NodeList | |
beforeEach(() => { | |
container = document.createElement('div') | |
container.innerHTML = nested_html | |
test_element = container.querySelector('#test-immediate-children') | |
children = Renderer.immediateChildren(test_element as HTMLElement) | |
}); | |
test('immediate children found', () => { | |
expect(children.length).toBe(2) | |
}) | |
test('descendants not included', () => { | |
let descendant_count = 0 | |
children.forEach( | |
child => { | |
let element = child as HTMLElement | |
descendant_count += (element.classList.contains('descendant-child')) ? 1 : 0 | |
} | |
) | |
expect(descendant_count).toBe(0) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment