-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ce6589
commit 303e51c
Showing
3 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const parse5 = require("parse5"); | ||
|
||
const readFile = function(filePath) { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), filePath), "utf8"); | ||
} catch (e) { | ||
assert(false, "The BookForm.vue file does not exist"); | ||
} | ||
|
||
return file; | ||
}; | ||
|
||
const parseFile = function(file) { | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ""), { | ||
locationInfo: true | ||
}); | ||
const nodes = doc.childNodes; | ||
|
||
return nodes; | ||
}; | ||
|
||
const getHtmlTag = function(tagName, nodes) { | ||
return nodes.filter(node => node.nodeName === tagName); | ||
}; | ||
|
||
module.exports.readFile = readFile; | ||
module.exports.parseFile = parseFile; | ||
module.exports.getHtmlTag = getHtmlTag; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const assert = require("chai").assert; | ||
const parse5 = require("parse5"); | ||
const cheerio = require("cheerio"); | ||
const helpers = require("../helpers"); | ||
|
||
describe("BookForm.vue", () => { | ||
it("should contain a checkbox with a `v-model` directive @book-form-will-contain-checkbox", () => { | ||
const file = helpers.readFile("src/components/BookForm.vue"); | ||
const nodes = helpers.parseFile(file); | ||
const tagName = helpers.getHtmlTag("template", nodes); | ||
const content = parse5.serialize(tagName[0].content); | ||
const $ = cheerio.load(content); | ||
const checkbox = $("form input[type=checkbox]"); | ||
|
||
assert( | ||
checkbox.length > 0, | ||
"The form doesn't have an `<input>` element with a `type` of `checkbox`" | ||
); | ||
|
||
assert.hasAnyKeys( | ||
checkbox.attr(), | ||
["v-model"], | ||
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value" | ||
); | ||
|
||
assert.propertyVal( | ||
checkbox.attr(), | ||
"v-model", | ||
"bookData.finishedReading", | ||
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value" | ||
); | ||
}); | ||
}); |
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