forked from orbit-oss/is
Add is.array overload that supports asserting array items (#119)
Co-authored-by: Pedro Augusto de Paula Barbosa <papb1996@gmail.com> Co-authored-by: Giora Guttsait <giora111@gmail.com> Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
parent
e31db97eab
commit
3f93bf200d
3 changed files with 54 additions and 4 deletions
24
test/test.ts
24
test/test.ts
|
|
@ -641,6 +641,30 @@ test('is.numericString', t => {
|
|||
|
||||
test('is.array', t => {
|
||||
testType(t, 'array', ['emptyArray']);
|
||||
|
||||
t.true(is.array([1, 2, 3], is.number));
|
||||
t.false(is.array([1, '2', 3], is.number));
|
||||
|
||||
t.notThrows(() => {
|
||||
assert.array([1, 2], assert.number);
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
assert.array([1, '2'], assert.number);
|
||||
});
|
||||
|
||||
t.notThrows(() => {
|
||||
const x: unknown[] = [1, 2, 3];
|
||||
assert.array(x, assert.number);
|
||||
x[0].toFixed(0);
|
||||
});
|
||||
|
||||
t.notThrows(() => {
|
||||
const x: unknown[] = [1, 2, 3];
|
||||
if (is.array<number>(x, is.number)) {
|
||||
x[0].toFixed(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('is.function', t => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue