diff --git a/test/unit/mocha/part6/refactor-book-form-method.spec.js b/test/unit/mocha/part6/refactor-book-form-method.spec.js index 0dac3025..ec9c2aa0 100644 --- a/test/unit/mocha/part6/refactor-book-form-method.spec.js +++ b/test/unit/mocha/part6/refactor-book-form-method.spec.js @@ -1,6 +1,8 @@ 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", () => { @@ -8,6 +10,10 @@ describe("BookForm.vue", () => { 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) { @@ -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" @@ -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()`" @@ -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." + ); }); });