Skip to content
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] 아놀드(한수빈) 미션 제출합니다. #10

Merged
merged 51 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b63fadd
build: tsconfig 설정
sanaandmomo Sep 26, 2022
ea35092
chore: jest 환경 설정
sanaandmomo Sep 26, 2022
e6b0b5b
chore: gitignore 설정
sanaandmomo Sep 26, 2022
3b9c571
feat: numberRange 만드는 유틸 타입
sanaandmomo Sep 26, 2022
12766b3
feat: fetch 타입 선언
sanaandmomo Sep 26, 2022
474d305
test: fetch 타입 테스트 작성
sanaandmomo Sep 26, 2022
fd357e0
feat: isNull 타입 선언
sanaandmomo Sep 26, 2022
e011a0d
test: isNull 타입 테스트
sanaandmomo Sep 26, 2022
49a291c
feat: isNil 타입 선언
sanaandmomo Sep 26, 2022
73105eb
test: isNil 타입 테스트 작성
sanaandmomo Sep 26, 2022
445c483
feat: isNumber 타입 선언
sanaandmomo Sep 26, 2022
27f7cd9
test: isNumber 타입 테스트 작성
sanaandmomo Sep 26, 2022
7156a96
feat: shuffle 타입 선언
sanaandmomo Sep 26, 2022
5cb1b9b
test: shuffle 타입 테스트
sanaandmomo Sep 26, 2022
54f61bf
feat: pick 타입 선언
sanaandmomo Sep 26, 2022
5ce5c29
test: pick 타입 테스트
sanaandmomo Sep 26, 2022
5a26472
feat: omit 타입 선언
sanaandmomo Sep 26, 2022
cf4cdb1
test: omit 타입 테스트
sanaandmomo Sep 26, 2022
608734c
feat: memoize 타입 선언
sanaandmomo Sep 27, 2022
1e4c987
test: memoize 타입 테스트
sanaandmomo Sep 27, 2022
962c2f5
feat: debounce 타입 선언
sanaandmomo Sep 27, 2022
b3adf88
test: debounce 타입 테스트
sanaandmomo Sep 27, 2022
b635d42
feat: throttle 타입 선언
sanaandmomo Sep 27, 2022
e0f2330
test: throttle 타입 테스트
sanaandmomo Sep 27, 2022
79dc6f7
feat: clickOutside 타입 선언
sanaandmomo Sep 27, 2022
5112804
test: clickOutside 타입 테스트
sanaandmomo Sep 27, 2022
267ce7b
feat: Node 인터페이스 확장
sanaandmomo Sep 27, 2022
e56cbb0
test: Node addEvent 타입 테스트
sanaandmomo Sep 27, 2022
9656a86
test: Node show, hidden 타입 테스트
sanaandmomo Sep 27, 2022
6f52b9c
test: Node innerHTML 타입 테스트
sanaandmomo Sep 27, 2022
a9279ce
feat: fetch 함수의 인자 url 타입 리터럴 타입으로 수정
sanaandmomo Sep 27, 2022
b35ad20
feat: isNull 함수 구현
sanaandmomo Sep 27, 2022
746acad
feat: isNil 함수 구현
sanaandmomo Sep 27, 2022
bbbd2e6
feat: isNumber 함수 구현
sanaandmomo Sep 27, 2022
69402ad
feat: isFunction 함수 구현
sanaandmomo Sep 27, 2022
d2709f0
feat: shuffle 함수 구현
sanaandmomo Sep 27, 2022
1945569
feat: pick 함수 구현
sanaandmomo Sep 27, 2022
e0a59c5
feat: memoize 구현
sanaandmomo Sep 27, 2022
375e258
feat: debounce 구현
sanaandmomo Sep 27, 2022
b6b3a43
feat: throttle 구현
sanaandmomo Sep 27, 2022
795f3ae
clickOutside 구현
sanaandmomo Sep 27, 2022
42a4938
build: 출력물 경로 수정
sanaandmomo Sep 27, 2022
f0e86f1
build: d.ts 파일만 생성하도록 설정
sanaandmomo Sep 27, 2022
c035e27
feat: dom util 타입 리팩터링 및 테스트 코드 수정
sanaandmomo Sep 27, 2022
9dc457c
feat: fetch 타입 선언
sanaandmomo Sep 27, 2022
a186246
test: 테스트 코드 test 함수로 래핑
sanaandmomo Sep 29, 2022
8e9f0e9
refactor: 중복되는 함수 타입 제거
sanaandmomo Sep 29, 2022
27672ed
refactor: thrrotle 함수의 arg 타입을 일치시키기
sanaandmomo Sep 29, 2022
dead710
feat: memoize, debounce, throttle args 타입 동기화
sanaandmomo Sep 29, 2022
96feecd
test: api 테스트
sanaandmomo Sep 29, 2022
00d3ec4
refactor: memoize, debounce, throttle 함수 타입 Parameters 를 통해 일관성 맞추기
sanaandmomo Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
47 changes: 32 additions & 15 deletions __tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,53 @@
import _ from '../src';

test('모듈은 기본 내보내기', () => {
expect(_).toBeTruthy();
expect(_).toBeTruthy();
});

test('모듈에 포함된 함수 확인', () => {
expect(typeof _.fetch).toBe('function');
expect(typeof _.fetch).toBe('function');
});

test('모듈에 포함된 함수 확인', () => {
expect(typeof _.pick).toBe('function');
expect(typeof _.pick).toBe('function');
});

test('모듈에 포함된 함수 확인', () => {
expect(typeof _.omit).toBe('function');
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 buttonElement = _('button.test-btn');

const buttonElement = _('button.test-btn');
expect(buttonElement).toBeTruthy();
expect(buttonElement).toBeTruthy();
});

test('innerHtml 동작을 확인한다.', () => {
const buttonElement = _('button.test-btn');

expect(buttonElement.innerHtml()).toBe('');
});

document.body.removeChild(buttonElement);
test('show 동작을 확인한다.', () => {
const buttonElement = _('button.test-btn');
buttonElement.show();

expect(buttonElement.getElement().style.display).toBe('block');
});

test('`_("").innerHTML()`~~~~', () => {});
test('hide 동작을 확인한다.', () => {
const buttonElement = _('button.test-btn');
buttonElement.hide();

expect(buttonElement.getElement().style.display).toBe('none');
});

test('`_("").show()`~~~~', () => {});
test('addEvent 동작을 확인한다.', () => {
const buttonElement = _('button.test-btn');
const listener = jest.fn();

test('`_("").hidden()`~~~~', () => {});
buttonElement.addEvent('click', listener);
buttonElement.getElement().click();

test('`_("").addEvent()`~~~~', () => {});
expect(listener).toBeCalled();
});
106 changes: 104 additions & 2 deletions __tests__/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,108 @@ import { expectType } from 'tsd';

import _ from '../src';

_('.button').addEvent('click', function (event) {
expectType<MouseEvent>(event);
const $button = _('button');

test('올바른 인자를 넣었을 때, 클릭 이벤트가 잘 작동한다', () => {
$button.addEvent('click', function (event) {
expectType<MouseEvent>(event);
});
});

test('이상한 이벤트 타입을 넣었을 때, 에러가 난다.', () => {
//@ts-expect-error
$button.addEvent('invalid eventType', function (event) {
console.log(event);
});
});

test('show의 반환 타입은 void이다.', () => {
expectType<void>($button.show());
});

test('hide의 반환 타입인 void이다.', () => {
expectType<void>($button.hide());
});

test('innerHtml의 반환 타입인 string이다.', () => {
expectType<string>($button.innerHtml('<div>a</div>'));
});

test('promise의 반환 타입은 Promise<string>이다.', () => {
expectType<Promise<string>>(
_.fetch<string>('https://example.com', {
method: 'GET',
}).then((res) => res.json())
);
});

test('isNull 테스트', () => {
expectType<boolean>(_.isNull(null));
expectType<boolean>(_.isNull(2));
expectType<boolean>(_.isNull(0));
});

test('isNil 테스트', () => {
expectType<boolean>(_.isNil(null));
expectType<boolean>(_.isNil(undefined));
expectType<boolean>(_.isNil(0));
});

test('isNumber 테스트', () => {
expectType<boolean>(_.isNumber(1));
expectType<boolean>(_.isNumber('1'));
});

test('isFunction 테스트', () => {
expectType<boolean>(_.isFunction(() => {}));
expectType<boolean>(_.isFunction('2'));
});

test('shuffle 테스트', () => {
expectType<(1 | 2 | 3 | 4)[]>(_.shuffle([1, 3, 2, 4]));
});

test('pick 테스트', () => {
expectType<{ a: 1; b: 2 }>(_.pick({ a: 1, b: 2, c: 3 }, 'a', 'b'));
});

test('omit 테스트', () => {
expectType<{ c: number }>(_.omit({ a: 1, b: 2, c: 3 }, 'a', 'b'));
});

test('memoize 테스트', () => {
expectType<() => 1>(
_.memoize(
() => 1,
() => '1'
)
);

expectType<(a: number, b: number) => number>(
_.memoize(
(a: number, b: number) => a + b,
(a: number, b: number) => `${a}+${b}`
)
);
});

test('debounce 테스트', () => {
expectType<() => void>(_.debounce(() => console.log('debounce'), 400));
});

test('throttle 테스트', () => {
expectType<() => void>(_.throttle(() => console.log('throttle'), 400));
});

test('clickOutside 테스트', () => {
expectType<void>(
_.clickOutside(document.createElement('div'), () =>
console.log('click outside')
)
);

expectType<void>(
//@ts-expect-error
_.clickOutside('div', () => console.log('click outside'))
);
});
Loading