Additional tests

This commit is contained in:
Angelos Chalaris
2018-11-07 15:03:27 +02:00
parent 3fb91e74d2
commit 81c975289c
5 changed files with 29 additions and 7 deletions

View File

@ -1,20 +1,19 @@
const expect = require('expect');
const { functionName } = require('./_30s.js');
let output = '';
const functionName = fn => fn.name;
test('functionName is a Function', () => {
expect(functionName).toBeInstanceOf(Function);
});
test('Works for native functions', () => {
expect(functionName(Math.max)).toBe('max');
expect(typeof functionName(Math.max)).toBe('function');
});
function fun(x) {
function f(x) {
return x;
}
test('Works for functions', () => {
expect(functionName(fun)).toBe('fun');
test('Works for normal functions', () => {
expect(typeof functionName(f)).toBe('function');
});
const fn = x => x;
test('Works for arrow functions', () => {
expect(functionName(fn)).toBe('fn');
expect(typeof functionName(x => x)).toBe('function');
});

View File

@ -4,3 +4,9 @@ const {hz} = require('./_30s.js');
test('hz is a Function', () => {
expect(hz).toBeInstanceOf(Function);
});
test('hz returns a number', () => {
expect(typeof hz(x => x)).toBe('number');
});
test('hz returns a number', () => {
expect(typeof hz(x => x, 10)).toBe('number');
});

View File

@ -4,3 +4,10 @@ const {insertAfter} = require('./_30s.js');
test('insertAfter is a Function', () => {
expect(insertAfter).toBeInstanceOf(Function);
});
let e = document.createElement('div');
e.setAttribute("id", "test");
test('Does not throw error if the element exists', () => {
expect(() => {
insertAfter(e, '<span>test</span>');
}).not.toThrow(TypeError);
});

View File

@ -4,3 +4,10 @@ const {insertBefore} = require('./_30s.js');
test('insertBefore is a Function', () => {
expect(insertBefore).toBeInstanceOf(Function);
});
let e = document.createElement('div');
e.setAttribute("id", "test");
test('Does not throw error if the element exists', () => {
expect(() => {
insertBefore(e, '<span>test</span>');
}).not.toThrow(TypeError);
});

View File

@ -4,3 +4,6 @@ const {isBrowserTabFocused} = require('./_30s.js');
test('isBrowserTabFocused is a Function', () => {
expect(isBrowserTabFocused).toBeInstanceOf(Function);
});
test('isBrowserTabFocused is a Function', () => {
expect(typeof isBrowserTabFocused()).toBe('boolean');
});