Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for template tags
Add failing tests for extracting selectors from HTML tags under
`<template>` tags.
  • Loading branch information
jarrodldavis committed Dec 10, 2018
commit e90bce19008081b239b708c9923758e371fc8d3a
34 changes: 34 additions & 0 deletions __tests__/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,37 @@ export const TEST_1_TAG = ["html", "head", "title", "body", "div", "a", "input"]
export const TEST_1_CLASS = ["test-container", "test-footer", "a-link"]

export const TEST_1_ID = ["a-link", "blo"]

export const TEST_2_CONTENT = `
<template>
<div id="app">
<div class="test-container">Well</div>
<div class="test-footer" id="an-id"></div>
<a href="#" id="a-link" class="a-link"></a>
<input id="blo" type="text" disabled/>
</div>
</template>

<script>
export default {
name: 'its-just-a-test'
}
</script>

<style>
.test-container {
color: darkgray;
text-align: center;
}

.test-footer {
font-weight: bold;
}
</style>
`

export const TEST_2_TAG = ["div", "a", "input"]

export const TEST_2_CLASS = ["test-container", "test-footer", "a-link"]

export const TEST_2_ID = ["a-link", "blo"]
32 changes: 32 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import purgehtml from "./../index.js"
import { TEST_1_CONTENT, TEST_1_TAG, TEST_1_CLASS, TEST_1_ID } from "./data"
import { TEST_2_CONTENT, TEST_2_TAG, TEST_2_CLASS, TEST_2_ID } from "./data"

describe("purgehtml", () => {
it("finds tag selectors", () => {
Expand Down Expand Up @@ -30,4 +31,35 @@ describe("purgehtml", () => {
expect(received.includes(item)).toBe(true)
}
})

describe("from a template tag", () => {
it("finds tag selectors", () => {
const received = purgehtml.extract(TEST_2_CONTENT)
for (let item of TEST_2_TAG) {
expect(received.includes(item)).toBe(true)
}
})

it("finds classes selectors", () => {
const received = purgehtml.extract(TEST_2_CONTENT)
for (let item of TEST_2_CLASS) {
expect(received.includes(item)).toBe(true)
}
})

it("finds id selectors", () => {
const received = purgehtml.extract(TEST_2_CONTENT)
for (let item of TEST_2_ID) {
expect(received.includes(item)).toBe(true)
}
})

it("finds all selectors", () => {
const received = purgehtml.extract(TEST_2_CONTENT)
const selectors = [...TEST_2_TAG, ...TEST_2_CLASS, ...TEST_2_ID]
for (let item of selectors) {
expect(received.includes(item)).toBe(true)
}
})
})
})