Skip to content

Commit

Permalink
feat: call; add jest coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 committed Nov 20, 2019
1 parent 62b460f commit 1599e55
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"description": "Awesome code implementation for Javascript",
"main": "index.js",
"scripts": {
"test": "jest",
"test": "jest --coverage",
"lint-staged": "lint-staged",
"lint-staged:ts": "tslint -c ./tslint.json src/**/**.ts",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
Expand Down
1 change: 1 addition & 0 deletions src/call/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### 原理
25 changes: 25 additions & 0 deletions src/call/__tests__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-20 19:26:53
*/

import '.';

function bar(name: string, age: number): object {
return {
name,
age
}
}

const callExpect1 = {
name: 'Rain120',
age: 23
}

test('bar call should callExpect1', () => {
// @ts-ignore
expect(bar._call(this, 'Rain120', 23)).toEqual(callExpect1);
});
16 changes: 16 additions & 0 deletions src/call/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-18 20:01:11
*/

type ObjectMap<V> = {
[name: string]: V;
};

// @ts-ignore
Function.prototype._call = function(context: ObjectMap<any>, ...arg: any): any {
context.fn = this;
return context.fn(...arg);
};
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
}
],
"use-isnan": true,
"interface-over-type-literal": false,
"variable-name": [true, "allow-leading-underscore", "ban-keywords", "check-format", "allow-pascal-case"],
"whitespace": [
true,
Expand Down

0 comments on commit 1599e55

Please sign in to comment.