|
| 1 | +<template> |
| 2 | + <p class="text">{{ message }}</p> |
| 3 | +</template> |
| 4 | + |
| 5 | +<script> |
| 6 | +
|
| 7 | +export default { |
| 8 | + data: () => ({ |
| 9 | + message: "Hello World!", |
| 10 | + }), |
| 11 | +} |
| 12 | +
|
| 13 | +</script> |
| 14 | + |
| 15 | +<style> |
| 16 | +
|
| 17 | +.text { |
| 18 | + color: blue; |
| 19 | +} |
| 20 | +
|
| 21 | +</style> |
| 22 | + |
| 23 | +<unit-test> |
| 24 | + |
| 25 | +import assert from "assert"; |
| 26 | + |
| 27 | +import Vue from "vue"; |
| 28 | +import Component from "./component.vue"; |
| 29 | + |
| 30 | +describe("component.vue", () => { |
| 31 | + it("exports an object", () => { |
| 32 | + assert.equal(typeof Component, "object"); |
| 33 | + }); |
| 34 | + |
| 35 | + describe("#data", () => { |
| 36 | + it("is a function", () => { |
| 37 | + assert.equal(typeof Component.data, "function"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("sets the default values", () => { |
| 41 | + assert.equal(Component.data().message, "Hello World!"); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe("rendering", () => { |
| 46 | + it("renders the correct message", () => { |
| 47 | + const Ctor = Vue.extend(Component); |
| 48 | + const el = document.createElement("div"); |
| 49 | + |
| 50 | + const vm = new Ctor({ el }).$mount(); |
| 51 | + |
| 52 | + assert.equal(vm.$el.textContent, "Hello World!"); |
| 53 | + }); |
| 54 | + |
| 55 | + it("renders the message with the correct class", () => { |
| 56 | + const Ctor = Vue.extend(Component); |
| 57 | + const el = document.createElement("div"); |
| 58 | + |
| 59 | + const vm = new Ctor({ el }).$mount(); |
| 60 | + |
| 61 | + assert(vm.$el.classList.contains("text")); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
| 66 | +</unit-test> |
0 commit comments