Skip to content

Commit

Permalink
feat: add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
nana4rider committed Jan 18, 2025
1 parent 578a98a commit d56aa8e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions __tests__/util/dataTransformUtil.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
getDecimalPlaces,
hex2ascii,
parseJson,
} from "@/util/dataTransformUtil";

describe("hex2ascii", () => {
test("正しく変換できる", () => {
const actual = hex2ascii("666f6f626172");

expect(actual).toBe("foobar");
});
});

describe("getDecimalPlaces", () => {
test("小数点あり", () => {
const actual = getDecimalPlaces(12.345);

expect(actual).toBe(3);
});

test("小数点なし", () => {
const actual = getDecimalPlaces(1234);

expect(actual).toBe(0);
});
});

describe("parseJson", () => {
test("変換できる", () => {
const actual = parseJson(`{"foo":1,"bar":"2"}`);

expect(actual).toEqual({
foo: 1,
bar: "2",
});
});

test("小数点なし", () => {
const actual = getDecimalPlaces(1234);

expect(actual).toBe(0);
});
});

0 comments on commit d56aa8e

Please sign in to comment.