-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Deno test", | ||
"type": "pwa-node", | ||
"request": "launch", | ||
"cwd": "${workspaceFolder}", | ||
"runtimeExecutable": "deno", | ||
"runtimeArgs": ["test", "--inspect-brk", "-A", "--unstable"], | ||
"attachSimplePort": 9229 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, { memo, PropsWithChildren } from "react"; | ||
export interface LoremIpsumProps {} | ||
|
||
const LoremIpsum = (({}: PropsWithChildren<LoremIpsumProps>) => { | ||
return <>LoremIpsum</>; | ||
}); | ||
|
||
export default memo(LoremIpsum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { forwardRef, memo } from "react"; | ||
type TypeRef = any; | ||
|
||
export interface LoremIpsumProps {} | ||
|
||
const LoremIpsum = forwardRef<TypeRef, LoremIpsumProps>(({}, ref) => { | ||
return <>LoremIpsum</>; | ||
}); | ||
|
||
export default memo(LoremIpsum); | ||
|
||
LoremIpsum.displayName = "LoremIpsum"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,37 @@ | ||
import { createReactComponentContent } from "./react-component.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import * as log from "https://deno.land/[email protected]/log/mod.ts"; | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
const readMockFile = async ( | ||
subPath: "react-component/LoremIpsum" | "react-component/LoremIpsumWithRef", | ||
) => { | ||
const url = new URL(import.meta.url); | ||
const pathname = decodeURI(url.pathname); | ||
|
||
return await Deno.readTextFile( | ||
path.resolve( | ||
pathname, | ||
`../__mocks__/${subPath}`, | ||
), | ||
); | ||
}; | ||
|
||
Deno.test( | ||
`createReactComponentContent("LoremIpsum", { | ||
forwardRef: false, | ||
}`, | ||
() => { | ||
`should return correct react component.`, | ||
async () => { | ||
assertEquals( | ||
createReactComponentContent("LoremIpsum", { | ||
forwardRef: false, | ||
}), | ||
`import React, { PropsWithChildren, memo } from "react"; | ||
export interface LoremIpsumProps {} | ||
const LoremIpsum = (({}: PropsWithChildren<LoremIpsumProps>) => { | ||
return <>LoremIpsum</>; | ||
}); | ||
export default memo(LoremIpsum);`, | ||
await readMockFile("react-component/LoremIpsum"), | ||
); | ||
}, | ||
); | ||
|
||
Deno.test( | ||
`createReactComponentContent("LoremIpsum", { | ||
forwardRef: true, | ||
})`, | ||
() => { | ||
assertEquals( | ||
createReactComponentContent("LoremIpsum", { | ||
forwardRef: true, | ||
}), | ||
`import React, { forwardRef, memo } from "react"; | ||
type TypeRef = any; | ||
export interface LoremIpsumProps {} | ||
const LoremIpsum = forwardRef<TypeRef, LoremIpsumProps>(({}, ref) => { | ||
return <>LoremIpsum</>; | ||
}); | ||
export default memo(LoremIpsum); | ||
LoremIpsum.displayName = "LoremIpsum";`, | ||
await readMockFile("react-component/LoremIpsumWithRef"), | ||
); | ||
}, | ||
); |