Skip to content

Commit

Permalink
Add test to Refactor method task
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinapowers committed Aug 2, 2018
1 parent 908e5cf commit 618998d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/unit/mocha/part6/refactor-book-form-method.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const assert = require("chai").assert;
const esquery = require("esquery");
const esprima = require("esprima");
const parse5 = require("parse5");
const cheerio = require("cheerio");
const helpers = require("../helpers");

describe("BookForm.vue", () => {
it("should contain a data function that returns a bookData object @book-form-emits-bookData", () => {
const file = helpers.readFile("src/components/BookForm.vue");
const nodes = helpers.parseFile(file);
const script = helpers.getHtmlTag("script", nodes);
const template = helpers.getHtmlTag("template", nodes);
const content = parse5.serialize(template[0].content);
const $ = cheerio.load(content);
const form = $("form");
let methods, bookSubmitMethod, bookDataParam, emmitBookData;

if (script.length == 0) {
Expand All @@ -29,6 +35,7 @@ describe("BookForm.vue", () => {
"Something went wrong and we weren't able to check your code."
);
}

assert(
methods.length > 0,
"The BookForm's `methods` declaration is not present"
Expand All @@ -44,7 +51,6 @@ describe("BookForm.vue", () => {
methods[0],
'Property[key.name="bookSubmit"] > FunctionExpression > Identifier[name="bookData"]'
);

assert(
bookDataParam.length > 0,
"We are not passing `bookData` as a parameter of `bookSubmit()`"
Expand All @@ -54,10 +60,16 @@ describe("BookForm.vue", () => {
methods[0],
'Property[key.name="bookSubmit"] > FunctionExpression > BlockStatement > .body > CallExpression .arguments[name="bookData"]'
);

assert(
emmitBookData.length > 0,
"We are not calling `this.$emit()` with `bookData` as its second argument."
);

assert.propertyVal(
form.attr(),
"v-on:submit.prevent",
"bookSubmit(bookData)",
"The `v-on:submit.prevent` directive should update the `bookSubmit` call to take `bookData` as its argument."
);
});
});

0 comments on commit 618998d

Please sign in to comment.