Additional tests
This commit is contained in:
@ -7,3 +7,6 @@ test('isPrime is a Function', () => {
|
||||
test('passed number is a prime', () => {
|
||||
expect(isPrime(11)).toBeTruthy();
|
||||
});
|
||||
test('passed number is not a prime', () => {
|
||||
expect(isPrime(10)).toBeFalsy();
|
||||
});
|
||||
|
||||
@ -12,6 +12,9 @@ test('Function works properly', () => {
|
||||
test('Function works properly', () => {
|
||||
expect(square(3)).toBe(9);
|
||||
});
|
||||
test('Function works properly, cache stores values (coverage)', () => {
|
||||
expect(square(3)).toBe(9);
|
||||
});
|
||||
test('Cache stores values', () => {
|
||||
expect(Array.from(square.cache)).toEqual([[2, 4], [3, 9]]);
|
||||
});
|
||||
|
||||
@ -4,3 +4,6 @@ const {nodeListToArray} = require('./_30s.js');
|
||||
test('nodeListToArray is a Function', () => {
|
||||
expect(nodeListToArray).toBeInstanceOf(Function);
|
||||
});
|
||||
test('nodeListToArray returns an array of proper length', () => {
|
||||
expect(nodeListToArray(document.childNodes).length).toBe(2);
|
||||
});
|
||||
|
||||
@ -4,3 +4,31 @@ const {off} = require('./_30s.js');
|
||||
test('off is a Function', () => {
|
||||
expect(off).toBeInstanceOf(Function);
|
||||
});
|
||||
test('off removes an event listener', () => {
|
||||
let el = document.createElement('div');
|
||||
let val = false;
|
||||
const fn = () => val = true;
|
||||
el.addEventListener('click', fn);
|
||||
off(el, 'click', fn);
|
||||
var clickEvent = new MouseEvent('click', {
|
||||
'view': window,
|
||||
'bubbles': true,
|
||||
'cancelable': false
|
||||
});
|
||||
el.dispatchEvent(clickEvent);
|
||||
expect(val).toBeFalsy();
|
||||
});
|
||||
test('off removes an event listener', () => {
|
||||
let el = document.createElement('div');
|
||||
let val = false;
|
||||
const fn = () => val = true;
|
||||
el.addEventListener('click', fn);
|
||||
off(el, 'click', fn, {});
|
||||
var clickEvent = new MouseEvent('click', {
|
||||
'view': window,
|
||||
'bubbles': true,
|
||||
'cancelable': false
|
||||
});
|
||||
el.dispatchEvent(clickEvent);
|
||||
expect(val).toBeFalsy();
|
||||
});
|
||||
|
||||
@ -4,3 +4,30 @@ const {on} = require('./_30s.js');
|
||||
test('on is a Function', () => {
|
||||
expect(on).toBeInstanceOf(Function);
|
||||
});
|
||||
test('on creates an event listener', () => {
|
||||
let el = document.createElement('div');
|
||||
let val = false;
|
||||
const fn = () => val = true;
|
||||
on(el, 'click', fn);
|
||||
var clickEvent = new MouseEvent('click', {
|
||||
'view': window,
|
||||
'bubbles': true,
|
||||
'cancelable': false
|
||||
});
|
||||
el.dispatchEvent(clickEvent);
|
||||
expect(val).toBeTruthy();
|
||||
});
|
||||
test('on creates an event listener', () => {
|
||||
let el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
let val = false;
|
||||
const fn = () => val = true;
|
||||
on(document.body, 'click', fn, { target: 'div' });
|
||||
var clickEvent = new MouseEvent('click', {
|
||||
'view': window,
|
||||
'bubbles': true,
|
||||
'cancelable': false
|
||||
});
|
||||
el.dispatchEvent(clickEvent);
|
||||
expect(val).toBeTruthy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user