-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TypeScript & Module Typing] 코이(정인교) 미션 제출합니다. #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,39 +1,45 @@ | ||||||
/** | ||||||
* @jest-environment jsdom | ||||||
*/ | ||||||
import _ from '../src'; | ||||||
import _ from "../src"; | ||||||
|
||||||
test('모듈은 기본 내보내기', () => { | ||||||
expect(_).toBeTruthy(); | ||||||
test("모듈은 기본 내보내기", () => { | ||||||
expect(_).toBeTruthy(); | ||||||
}); | ||||||
|
||||||
test('모듈에 포함된 함수 확인', () => { | ||||||
expect(typeof _.fetch).toBe('function'); | ||||||
test("모듈에 포함된 함수 확인", () => { | ||||||
expect(typeof _.fetch).toBe("function"); | ||||||
}); | ||||||
|
||||||
test('모듈에 포함된 함수 확인', () => { | ||||||
expect(typeof _.pick).toBe('function'); | ||||||
test("모듈에 포함된 함수 확인", () => { | ||||||
expect(typeof _.pick).toBe("function"); | ||||||
}); | ||||||
|
||||||
test('모듈에 포함된 함수 확인', () => { | ||||||
expect(typeof _.omit).toBe('function'); | ||||||
test("모듈에 포함된 함수 확인", () => { | ||||||
expect(typeof _.omit).toBe("function"); | ||||||
}); | ||||||
|
||||||
test('Selector 동작 확인', () => { | ||||||
const divElement = document.createElement('div'); | ||||||
divElement.innerHTML = `<button class='test-btn'>Continue</button>`; | ||||||
document.body.appendChild(divElement); | ||||||
test("Selector 동작 확인", () => { | ||||||
const divElement = document.createElement("div"); | ||||||
divElement.innerHTML = `<button class='test-btn'>Continue</button>`; | ||||||
document.body.appendChild(divElement); | ||||||
|
||||||
const buttonElement = _('button.test-btn'); | ||||||
expect(buttonElement).toBeTruthy(); | ||||||
const buttonElement = _("button.test-btn"); | ||||||
expect(buttonElement).toBeTruthy(); | ||||||
|
||||||
document.body.removeChild(buttonElement); | ||||||
document.body.removeChild(buttonElement); | ||||||
}); | ||||||
|
||||||
test('`_("").innerHTML()`~~~~', () => {}); | ||||||
|
||||||
test('`_("").show()`~~~~', () => {}); | ||||||
|
||||||
test('`_("").hidden()`~~~~', () => {}); | ||||||
test("show 동작 확인", () => { | ||||||
const buttonElement = _("button.test-btn"); | ||||||
buttonElement.style.display = "hidden"; | ||||||
buttonElement.show(); | ||||||
expect(buttonElement.style.display).toBe("block"); | ||||||
}); | ||||||
|
||||||
test('`_("").addEvent()`~~~~', () => {}); | ||||||
test("hidden 동작 확인", () => { | ||||||
const buttonElement = _("button.test-btn"); | ||||||
buttonElement.style.display = "block"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. show 함수를 사용해주세요 :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니당 |
||||||
buttonElement.hide(); | ||||||
expect(buttonElement.style.display).toBe("hidden"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 none이 맞겠네요 😅 |
||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { expectType } from 'tsd'; | ||
import { expectType } from "tsd"; | ||
|
||
import _ from '../src'; | ||
import _ from "../src"; | ||
|
||
_('.button').addEvent('click', function (event) { | ||
expectType<MouseEvent>(event); | ||
_(".button").addEvent("click", function (event: MouseEvent) { | ||
expectType<MouseEvent>(event); | ||
}); | ||
|
||
expectType<boolean>(_.isNull(null)); | ||
|
||
expectType<boolean>(_.isNull(null)); | ||
|
||
expectType<boolean>(_.isNumber(3)); | ||
|
||
expectType<boolean>(_.isFunction(3)); | ||
|
||
expectType<string[]>(_.shuffle(["a", "b", "c"])); | ||
|
||
const obj = { a: 1, b: 2, c: 3 }; | ||
|
||
expectType<Pick<typeof obj, "a">>(_.pick(obj, ["a"])); | ||
|
||
expectType<Omit<typeof obj, "a">>(_.omit(obj, ["a"])); | ||
|
||
const func = () => {}; | ||
|
||
expectType<typeof func>(_.debounce(func, 1000)); | ||
|
||
expectType<typeof func>(_.throttle(func, 1000)); | ||
|
||
expectType<(target: HTMLElement, event: HTMLElement) => boolean>( | ||
_.clickOutside | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
verbose: true, | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
declare global { | ||
interface HTMLElement extends CustomElement { | ||
} | ||
} | ||
interface CustomElement { | ||
innerHtml: (html: string) => string; | ||
hide: () => void; | ||
show: () => void; | ||
addEvent: <T extends keyof HTMLElementEventMap>(type: T, handler: (event: HTMLElementEventMap[T]) => void) => void; | ||
} | ||
declare function _(selector: string): HTMLElement; | ||
declare module _ { | ||
function fetch<T>(url: string, config: RequestInit): Promise<T>; | ||
function isNull<T>(value: T): boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generic T를 왜 받는건가요? |
||
function isNil<T>(value: T): boolean; | ||
function isNumber<T>(value: T): boolean; | ||
function isFunction<T>(value: T): boolean; | ||
function shuffle<T>(collection: T[]): T[]; | ||
function pick<T extends Record<string, unknown>, K extends Partial<keyof T>>(obj: T, paths: K[]): Pick<T, K>; | ||
function omit<T extends Record<string, unknown>, K extends Partial<keyof T>>(obj: T, paths: K[]): Omit<T, K>; | ||
function memoize<T, K>(func: (...args: T[]) => K, resolver: (...args: T[]) => string): (...args: T[]) => K; | ||
function debounce<T, K>(func: (...args: T[]) => K, wait?: number): (...args: T[]) => any; | ||
function throttle<T, K>(func: (...args: T[]) => K, wait?: number): (...args: T[]) => any; | ||
function clickOutside(target: HTMLElement, element: HTMLElement): boolean; | ||
} | ||
export default _; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.