Skip to content

Commit 9d54221

Browse files
committed
test: SketchyBtn tests completed
1 parent aad8034 commit 9d54221

File tree

7 files changed

+69
-9
lines changed

7 files changed

+69
-9
lines changed

docs/unit-tests/sketchy-btn.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SketchyDiv Component Tests
2+
3+
These are some unit test cases for SketchyBtn component
4+
5+
## Rendering
6+
7+
- render on the screen
8+
9+
## Props
10+
11+
- label is rendered
12+
13+
## Events
14+
15+
- emit `click` event when clicked
16+
17+
## Methods
18+
19+
- _no tests specified_
20+
21+
## Slots
22+
23+
- _no tests specified_
24+
25+
## Accessibility
26+
27+
- _no tests specified_

docs/unit-tests/sketchy-div.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
# SketchyDiv Component Tests
2+
23
These are some unit test cases for SketchyDiv component
34

45
## Rendering
6+
57
- container div exist
68
- canvas size is not 0 if container is greator then 0
79

8-
910
## Props
11+
1012
- classes passed to it are classes of the container div
1113

1214
## Events
15+
1316
- emit `click` event when clicked
1417

1518
## Methods
16-
- *no tests specified*
19+
20+
- _no tests specified_
1721

1822
## Slots
23+
1924
- render a div that is passed in the slot
2025

2126
## Accessibility
22-
- *no tests specified*
27+
28+
- _no tests specified_

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"dev": "vite",
4545
"build": "vite build",
4646
"preview": "vite preview",
47-
"test:unit": "vitest"
47+
"test:unit": "vitest run"
4848
},
4949
"dependencies": {
5050
"roughjs": "^4.6.6",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { mount, shallowMount } from "@vue/test-utils";
2+
import { describe, expect, test } from "vitest";
3+
import SketchyBtn from "./SketchyBtn.vue";
4+
import { render } from "@testing-library/vue";
5+
6+
describe("SketchyBtn", () => {
7+
test("render on the scree", () => {
8+
const wrapper = shallowMount(SketchyBtn);
9+
expect(wrapper.exists()).toBe(true);
10+
});
11+
12+
test("label is rendered", () => {
13+
const label = "Button";
14+
const wrapper = mount(SketchyBtn, {
15+
props: {
16+
label: label,
17+
},
18+
});
19+
expect(wrapper.text()).toContain(label);
20+
});
21+
22+
test("emit `click` event when clicked", async () => {
23+
const wrapper = shallowMount(SketchyBtn);
24+
await wrapper.trigger("click");
25+
expect(wrapper.emitted().click).toBeTruthy();
26+
});
27+
});

lib/src/components/sketchydiv/SketchyDiv.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("SketchyDiv", () => {
88
const wrapper = render(SketchyDiv);
99
expect(wrapper.container.firstChild.tagName).toBe("DIV");
1010
});
11+
1112
test("canvas size is not 0 if container is greator then 0", () => {
1213
const wrapper = render(SketchyDiv, {
1314
attrs: {
@@ -18,6 +19,7 @@ describe("SketchyDiv", () => {
1819
expect(canvas.width).toBeGreaterThan(0);
1920
expect(canvas.height).toBeGreaterThan(0);
2021
});
22+
2123
test("classes passed to it are classes of the container div", () => {
2224
const wrapper = render(SketchyDiv, {
2325
attrs: {
@@ -27,6 +29,7 @@ describe("SketchyDiv", () => {
2729
const containerDiv = wrapper.container.firstChild;
2830
expect(containerDiv).toHaveClass("cls1");
2931
});
32+
3033
test("emit `click` event when clicked", async () => {
3134
const wrapper = render(SketchyDiv, {
3235
attrs: {
@@ -37,6 +40,7 @@ describe("SketchyDiv", () => {
3740
await fireEvent.click(containerDiv);
3841
expect(wrapper.emitted().click).toBeTruthy();
3942
});
43+
4044
test("render a div that is passed in the slot", () => {
4145
const slotContent =
4246
'<div data-testid="slot-div">This is inside SketchyDiv</div>';

lib/src/components/sketchydiv/SketchyDiv.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,14 @@ export default {
8787
}
8888
8989
onMounted(() => {
90-
console.log("onMounted, outNext", containerRef.value.clientHeight)
9190
nextTick(() => {
92-
console.log("onMounted, inNext", containerRef.value.clientHeight)
9391
size.value.width = containerRef.value.clientWidth;
9492
size.value.height = containerRef.value.clientHeight;
9593
drawDiv();
9694
});
9795
});
9896
onUpdated(() => {
99-
console.log("onUpdated, outNext", containerRef.value.clientHeight)
10097
nextTick(() => {
101-
console.log("onUpdated, inNext", containerRef.value.clientHeight)
10298
size.value.width = containerRef.value.clientWidth;
10399
size.value.height = containerRef.value.clientHeight;
104100
clearCanvas();

lib/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
browser: {
1111
enabled: true,
1212
name: "firefox",
13-
// headless: true,
13+
headless: true,
1414
provider: "playwright",
1515
// https://playwright.dev
1616
providerOptions: {},

0 commit comments

Comments
 (0)