Skip to content

Commit

Permalink
test two more spans
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed Jul 27, 2024
1 parent 61c9077 commit 1329e81
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/SpanBoolean.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<span
><b :style="'color:' + color">{{ text }}</b></span
><b :style="'color:' + color" data-testid="booleanSpan">{{ text }}</b></span
>
</template>

Expand Down
2 changes: 1 addition & 1 deletion src/components/SpanDate.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<span>{{ dateString }}</span>
<span data-testid="dateSpan">{{ dateString }}</span>
</template>

<script lang="ts" setup>
Expand Down
23 changes: 23 additions & 0 deletions src/tests/components/SpanBoolean.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render, screen } from "@testing-library/vue";
import { expect, test } from "vitest";
import "@testing-library/jest-dom/vitest";
import SpanBoolean from "@/components/SpanBoolean.vue";

const green = "rgb(0, 128, 0)";
const red = "rgb(255, 0, 0)";

test("test true", async () => {
render(SpanBoolean, { props: { value: true } });
const booleanSpan = screen.getByTestId<HTMLElement>("booleanSpan");
expect(booleanSpan.textContent).toEqual("yes");
const styles = getComputedStyle(booleanSpan);
expect(styles.color).toBe(green);
});

test("test false", async () => {
render(SpanBoolean, { props: { value: false } });
const booleanSpan = screen.getByTestId<HTMLElement>("booleanSpan");
expect(booleanSpan.textContent).toEqual("no");
const styles = getComputedStyle(booleanSpan);
expect(styles.color).toBe(red);
});
18 changes: 18 additions & 0 deletions src/tests/components/SpanDate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen } from "@testing-library/vue";
import { expect, test } from "vitest";
import "@testing-library/jest-dom/vitest";
import SpanDate from "@/components/SpanDate.vue";

const date = new Date(Date.parse("2020-03-04"));

test("test date locale formatting", async () => {
render(SpanDate, { props: { date: date } });
const dateSpan = screen.getByTestId<HTMLSpanElement>("dateSpan");
expect(dateSpan.textContent).toEqual("03/04/2020");
});

test("test date empty no error", async () => {
render(SpanDate);
const dateSpan = screen.getByTestId<HTMLSpanElement>("dateSpan");
expect(dateSpan).toBeEmptyDOMElement();
});

0 comments on commit 1329e81

Please sign in to comment.