Files
30-seconds-of-code/test/toSafeInteger.test.js
Christian C. Salvadó 83a6a6ea32 [ENHANCEMENT] Properly configure eslint to work with jest (#988)
* chore: make aware eslint that we use jest

By setting up the jest environment, we no longer need to declare the
'test' global in the configuration.

* chore: don't need to import expect, it's a jest environment global

* chore: don't need to import expect when creating undefined test
2019-06-18 08:34:45 +03:00

42 lines
1.3 KiB
JavaScript

const {toSafeInteger} = require('./_30s.js');
test('toSafeInteger is a Function', () => {
expect(toSafeInteger).toBeInstanceOf(Function);
});
test('Number(toSafeInteger(3.2)) is a number', () => {
expect(Number(toSafeInteger(3.2))).toBeTruthy();
});
test('Converts a value to a safe integer', () => {
expect(toSafeInteger(3.2)).toBe(3);
});
test("toSafeInteger('4.2') returns 4", () => {
expect(toSafeInteger('4.2')).toBe(4);
});
test('toSafeInteger(4.6) returns 5', () => {
expect(toSafeInteger(4.6)).toBe(5);
});
test('toSafeInteger([]) returns 0', () => {
expect(toSafeInteger([])).toBe(0);
});
test('isNaN(toSafeInteger([1.5, 3124])) is true', () => {
expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy();
});
test("isNaN(toSafeInteger('string')) is true", () => {
expect(isNaN(toSafeInteger('string'))).toBeTruthy();
});
test('isNaN(toSafeInteger({})) is true', () => {
expect(isNaN(toSafeInteger({}))).toBeTruthy();
});
test('isNaN(toSafeInteger()) is true', () => {
expect(isNaN(toSafeInteger())).toBeTruthy();
});
test('toSafeInteger(Infinity) returns 9007199254740991', () => {
expect(toSafeInteger(Infinity)).toBe(9007199254740991);
});
let start = new Date().getTime();
toSafeInteger(3.2);
let end = new Date().getTime();
test('toSafeInteger(3.2) takes less than 2s to run', () => {
expect(end - start < 2000).toBeTruthy();
});