Files
30-seconds-of-code/test/isPrimitive.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 {isPrimitive} = require('./_30s.js');
test('isPrimitive is a Function', () => {
expect(isPrimitive).toBeInstanceOf(Function);
});
test('isPrimitive(null) is primitive', () => {
expect(isPrimitive(null)).toBeTruthy();
});
test('isPrimitive(undefined) is primitive', () => {
expect(isPrimitive(undefined)).toBeTruthy();
});
test('isPrimitive(string) is primitive', () => {
expect(isPrimitive('string')).toBeTruthy();
});
test('isPrimitive(true) is primitive', () => {
expect(isPrimitive(true)).toBeTruthy();
});
test('isPrimitive(50) is primitive', () => {
expect(isPrimitive(50)).toBeTruthy();
});
test("isPrimitive('Hello') is primitive", () => {
expect(isPrimitive('Hello')).toBeTruthy();
});
test('isPrimitive(false) is primitive', () => {
expect(isPrimitive(false)).toBeTruthy();
});
test('isPrimitive(Symbol()) is primitive', () => {
expect(isPrimitive(Symbol())).toBeTruthy();
});
test('isPrimitive([1, 2, 3]) is not primitive', () => {
expect(isPrimitive([1, 2, 3])).toBeFalsy();
});
test('isPrimitive({ a: 123 }) is not primitive', () => {
expect(isPrimitive({ a: 123 })).toBeFalsy();
});
let start = new Date().getTime();
isPrimitive({ a: 123 });
let end = new Date().getTime();
test('isPrimitive({ a: 123 }) takes less than 2s to run', () => {
expect(end - start < 2000).toBeTruthy();
});