From d293ac3aa4d9aa378f2d1f900756fb06674ec265 Mon Sep 17 00:00:00 2001 From: "S.long" Date: Fri, 28 Aug 2020 15:36:20 +0700 Subject: [PATCH] add sample 2 --- .gitignore | 4 ++-- example/index.js | 6 ++++++ example/package.json | 14 ++++++++++++++ package.json | 3 ++- src/index.ts | 4 +++- src/sample2.ts | 11 +++++++++++ test/sample.test.js | 16 ++++++++-------- test/sample2.test.js | 25 +++++++++++++++++++++++++ 8 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 example/index.js create mode 100644 example/package.json create mode 100644 src/sample2.ts create mode 100644 test/sample2.test.js diff --git a/.gitignore b/.gitignore index 59f2945..fa5ff87 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,10 @@ .vscode # Lock File -yarn.lock +**/yarn.lock # Node Modules -node_modules +**/node_modules # Built dist diff --git a/example/index.js b/example/index.js new file mode 100644 index 0000000..21bf570 --- /dev/null +++ b/example/index.js @@ -0,0 +1,6 @@ +const { sample } = require("lib-name") + +console.log("Example : ") +console.log("==========================") +console.log("Result of 2 = ", sample(2)) +console.log("Result of 4 = ", sample(4)) diff --git a/example/package.json b/example/package.json new file mode 100644 index 0000000..e97f181 --- /dev/null +++ b/example/package.json @@ -0,0 +1,14 @@ +{ + "name": "lib-example", + "version": "1.0.0", + "description": "Example of Develop Library", + "main": "index.js", + "license": "MIT", + "private": false, + "dependencies": { + "lib-name": "link:../" + }, + "scripts": { + "start": "node index.js" + } +} diff --git a/package.json b/package.json index 1940924..14bb476 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "scripts": { "build": "tsc", "test": "jest", - "build:test": "yarn jest && yarn build" + "build:test": "yarn jest && yarn build", + "run:example": "cd example && yarn start" }, "devDependencies": { "@babel/core": "^7.11.4", diff --git a/src/index.ts b/src/index.ts index a0380c5..8d6b961 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ -export { default as sample } from "./sample" +export { default as power } from "./sample" + +export { default as sqrt } from "./sample2" diff --git a/src/sample2.ts b/src/sample2.ts new file mode 100644 index 0000000..78a079a --- /dev/null +++ b/src/sample2.ts @@ -0,0 +1,11 @@ +const sqrt = (n : number): number | undefined => { + if( typeof n === "undefined" || n === null){ + return undefined + } + if(typeof n !== "number"){ + return undefined + } + return Math.sqrt(n) +} + +export default sqrt diff --git a/test/sample.test.js b/test/sample.test.js index a3404dd..3bfb36a 100644 --- a/test/sample.test.js +++ b/test/sample.test.js @@ -1,25 +1,25 @@ -import {sample} from "../src" +import {power} from "../src" // Describe : top level to describe a block of test below is for what describe("Test Sample Function", () => { // Test : is run for each test test("Test N is Undefined", () => { - expect(sample(undefined)).toBe(undefined) // expect sample(undefined) return undefined + expect(power(undefined)).toBe(undefined) // expect sample(undefined) return undefined }) test("Test N is Null", () => { - expect(sample(null)).toBe(undefined) + expect(power(null)).toBe(undefined) }) test("Test N is not number",() => { - expect(sample("Hello")).toBe(undefined) + expect(power("Hello")).toBe(undefined) }) test("Test Normal Number",() => { - expect(sample(0)).toBe(0) - expect(sample(1)).toBe(1) - expect(sample(2)).toBe(4) - expect(sample(100)).toBe(10000) + expect(power(0)).toBe(0) + expect(power(1)).toBe(1) + expect(power(2)).toBe(4) + expect(power(100)).toBe(10000) }) }) diff --git a/test/sample2.test.js b/test/sample2.test.js new file mode 100644 index 0000000..d3c65a2 --- /dev/null +++ b/test/sample2.test.js @@ -0,0 +1,25 @@ +import {sqrt} from "../src" + +// Describe : top level to describe a block of test below is for what +describe("Test Sample 2 Function", () => { + // Test : is run for each test + test("Test N is Undefined", () => { + expect(sqrt(undefined)).toBe(undefined) // expect sample(undefined) return undefined + }) + + test("Test N is Null", () => { + expect(sqrt(null)).toBe(undefined) + }) + + test("Test N is not number",() => { + expect(sqrt("Hello")).toBe(undefined) + }) + + test("Test Normal Number",() => { + expect(sqrt(0)).toBe(0) + expect(sqrt(1)).toBe(1) + expect(sqrt(4)).toBe(2) + expect(sqrt(10000)).toBe(100) + }) + +})