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:
Arnovsky 2020-07-25 10:11:59 +03:00 committed by GitHub
parent e31db97eab
commit 3f93bf200d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 4 deletions

View file

@ -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 => {