update test sample
This commit is contained in:
parent
5c58eef706
commit
9ced30ded5
@ -1 +1,3 @@
|
|||||||
console.log('heeee');
|
|
||||||
|
|
||||||
|
export { default as sample } from "./sample"
|
||||||
|
11
src/sample.ts
Normal file
11
src/sample.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const power = (n? : number) : number | undefined => {
|
||||||
|
if( typeof n === "undefined" || n === null){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
if(typeof n !== "number"){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return Math.pow(n, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default power
|
25
test/sample.test.js
Normal file
25
test/sample.test.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import {sample} 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
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Test N is Null", () => {
|
||||||
|
expect(sample(null)).toBe(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Test N is not number",() => {
|
||||||
|
expect(sample("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)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user