Skip to content

Commit

Permalink
Merge pull request #19 from pluralsight-projects/more-test-tweaks
Browse files Browse the repository at this point in the history
More test tweaks
  • Loading branch information
jonfriskics committed May 15, 2018
2 parents 78c762d + b5a0c52 commit 2d6e4ea
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"start": "npm run dev",
"unit:part1": "npm run unit -- --part part1",
"unit:part2": "npm run unit -- --part part2",
"mocha": "NODE_ENV=test mocha 'test/unit/mocha/**/*.spec.js'",
"mocha:part1": "NODE_ENV=test mocha 'test/unit/mocha/part1/*.spec.js'",
"mocha:part2": "NODE_ENV=test mocha 'test/unit/mocha/part2/*.spec.js'",
"mocha:part3": "NODE_ENV=test mocha 'test/unit/mocha/part3/*.spec.js'",
"mocha:part4": "NODE_ENV=test mocha 'test/unit/mocha/part4/*.spec.js'",
"mocha:part5": "NODE_ENV=test mocha 'test/unit/mocha/part5/*.spec.js'",
"mocha": "NODE_ENV=test mocha 'test/unit/mocha/**/*.spec.js' || true",
"mocha:part1": "NODE_ENV=test mocha 'test/unit/mocha/part1/*.spec.js' || true",
"mocha:part2": "NODE_ENV=test mocha 'test/unit/mocha/part2/*.spec.js' || true",
"mocha:part3": "NODE_ENV=test mocha 'test/unit/mocha/part3/*.spec.js' || true",
"mocha:part4": "NODE_ENV=test mocha 'test/unit/mocha/part4/*.spec.js' || true",
"mocha:part5": "NODE_ENV=test mocha 'test/unit/mocha/part5/*.spec.js' || true",
"test": "npm run mocha",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
"build": "node build/build.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ describe('BookList.vue', () => {
// Test for booklist in the app div
const results = document.querySelector('h1');
assert(results != null, "The BookList template does not contain an h1 tag")
assert(results.innerHTML === '{{title}}', 'The BookList template does not contain the `{{title}}` in an `h1`');
let re = /\{\{\s*title\s*\}\}/g
let match = results.innerHTML.match(re)
assert(match != null && match.length == 1, 'The BookList template does not contain the `{{title}}` in an `h1`');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('BookItem.vue', () => {
const nodes = doc.childNodes;
const styles = nodes.filter(node => node.nodeName === 'style');
if (styles.length == 0) {
assert(false, "The BookList.vue file does not contain a style element.")
assert(false, "The BookItem.vue file does not contain a style element.")
}
if (styles[0].childNodes.length == 0) {
assert(false, "The BookList style tag does not contain any CSS rules.")
assert(false, "The BookItem style tag does not contain any CSS rules.")
}
const style = styles[0].childNodes[0].value;
const parsed = cssom.parse(style);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mocha/part3/book-item-contains-props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('BookItem.vue', () => {
let results = esquery(ast, 'ExportDefaultDeclaration Property[key.name="name"] Literal[value="BookItem"]');
assert(results.length > 0, 'The BookItem component does not have a `name` property with the value of `BookItem` defined in the `export default` section');

results = esquery(ast, 'ExportDefaultDeclaration Property[key.name="props"] Literal[value="book"]');
assert(results.length > 0, 'The BookItem component does not have a `props` property with an array value containing the string `book` defined in the `export default` section');
results = esquery(ast, 'ExportDefaultDeclaration Property[key.name="props"]');
assert(results.length > 0 && results[0].value.type == 'ArrayExpression' && results[0].value.elements[0].value == 'book', 'The BookItem component does not have a `props` property with an array value containing the string `book` defined in the `export default` section');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ describe('BookList.vue', () => {
const script = nodes.filter(node => node.nodeName === 'script');

// Test for correct import statement
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });

let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "It looks like your import statement is missing a semicolon at the end.")
}

let results = esquery(ast, 'ImportDeclaration[source.value="./BookItem"]');
assert(results.length > 0, 'The `BookItem` class was not imported from `./BookItem` In BookList.vue');

Expand Down
8 changes: 7 additions & 1 deletion test/unit/mocha/part4/book-list-contains-book-item.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ describe('BookList.vue', () => {
const script = nodes.filter(node => node.nodeName === 'script');

// Test for bookList definition in the component key
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "It looks like your import statement is missing a semicolon at the end.")
}

const results = esquery(ast, 'Property[key.name=components] > ObjectExpression > Property[key.name=BookItem]');
assert(results.length > 0, 'The value of the `components` property is not an object containing `BookItem` in BookList.vue');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ describe('BookList.vue', () => {
assert(false, "We either didn't find a script tag, or any code in a script tag in the BookForm component.")
}

const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "Something went wrong and we weren't able to check your code.")
}

const methods = esquery(ast, 'Property[key.name=methods]');
assert(methods.length > 0, 'The BookList\'s `methods` declaration is not present');
});
Expand Down

0 comments on commit 2d6e4ea

Please sign in to comment.