Files
30-seconds-of-code/test/last.test.js
Christian Melgarejo Bresanovich ec28d5fa6f Update snippets head and last to type check
Update `head` and `last` to check on empty, undefined, null arrays.
2019-12-11 03:17:18 -03:00

33 lines
1.0 KiB
JavaScript

const {last} = require('./_30s.js');
test('last is a Function', () => {
expect(last).toBeInstanceOf(Function);
});
test('last({ a: 1234}) returns undefined', () => {
expect(last({ a: 1234 }) === undefined).toBeTruthy();
});
test('last([1, 2, 3]) returns 3', () => {
expect(last([1, 2, 3])).toBe(3);
});
test('last({ 0: false}) returns undefined', () => {
expect(last({ 0: false })).toBe(undefined);
});
test('last(String) returns g', () => {
expect(last('String')).toBe('g');
});
test('last(null) returns undefined', () => {
expect(last(null)).toBe(undefined);
});
test('last(undefined) returns undefined', () => {
expect(last(undefined)).toBe(undefined);
});
test('last() returns undefined', () => {
expect(last()).toBe(undefined);
});
let start = new Date().getTime();
last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
let end = new Date().getTime();
test('last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
expect(end - start < 2000).toBeTruthy();
});