-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
49 additions
and
34 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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
# EditorConfig: http://EditorConfig.org | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{js,d.ts,ts}] | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# 2 space indentation | ||
[*.yaml, *.yml] | ||
[package.json,*.yaml] | ||
indent_style = space | ||
indent_size = 2 |
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 @@ | ||
* text=auto eol=lf |
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,5 +1,6 @@ | ||
# Global | ||
node_modules/ | ||
coverage | ||
|
||
# OS Generated | ||
.DS_Store* | ||
|
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
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,5 @@ | ||
interface Options { | ||
min?: number; | ||
max?: number; | ||
} | ||
export default function integer(options?: Options): number; |
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
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,6 @@ | ||
import {expectType} from 'tsd'; | ||
import integer from './index.js'; | ||
|
||
expectType<number>(integer()); | ||
expectType<number>(integer({min: 0})); | ||
expectType<number>(integer({min: 0, max: 10})); |
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
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,34 +1,26 @@ | ||
import integer from './index.js'; | ||
import test from 'ava'; | ||
import integer from './index.js'; | ||
|
||
test('integer return type to be number', t => { | ||
t.is(typeof integer(), 'number'); | ||
t.is(typeof integer(), 'number'); | ||
}); | ||
|
||
test('integer with number min 0 return type to be number', t => { | ||
t.is(typeof integer({min: 0}), 'number'); | ||
t.is(typeof integer({min: 0}), 'number'); | ||
}); | ||
|
||
test('integer with number min 0 and max 10 return type to be number', t => { | ||
t.is(typeof integer({min: 0, max: 10}), 'number'); | ||
t.is(typeof integer({min: 0, max: 10}), 'number'); | ||
}); | ||
|
||
test('integer with number min 0 and max 10 less than 11', t => { | ||
t.true(integer({min: 0, max: 10}) < 11); | ||
t.true(integer({min: 0, max: 10}) < 11); | ||
}); | ||
|
||
test('integer with string to thow error on string', t => { | ||
const error = t.throws(() => { | ||
integer({min: 'string'}) | ||
}, {instanceOf: TypeError}); | ||
test('integer with string to thow error on min > max', t => { | ||
const error = t.throws(() => { | ||
integer({min: 10, max: 0}); | ||
}, {instanceOf: TypeError}); | ||
|
||
t.is(error.message, 'Expected all arguments to be numbers.'); | ||
t.is(error.message, 'Min cannot be greater than Max.'); | ||
}); | ||
|
||
test('integer with string to thow error on min > max', t => { | ||
const error = t.throws(() => { | ||
integer({min: 10, max: 0}) | ||
}, {instanceOf: TypeError}); | ||
|
||
t.is(error.message, 'Min cannot be greater than Max.'); | ||
}); |