Skip to content

Instantly share code, notes, and snippets.

View mauteri's full-sized avatar

Mike Auteri mauteri

View GitHub Profile
public function closest_image_size( $width, $height, $photos ) {
foreach( $photos as $photo ) {
if( $width <= $photo['width'] && $height <= $photo['height'] ) {
$w = $photo['width'] - $width;
$h = $photo['height'] - $height;
if( !isset($source) ) {
$sum = $w + $h;
$source = $photo['source'];
} else if( $sum > ( $w + $h ) ) {
$sum = $w + $h;
@mauteri
mauteri / gist:55f87b8ae004b6abb77822b37d4fd625
Created July 16, 2021 21:54
addListItem DOM Manipulation Jest Test
import {addListItem} from '../index';
describe('addListItem', () => {
beforeAll(() => {
document.body.innerHTML = '<ul id="unittest"></ul>';
const $el = document.getElementById('unittest')
addListItem($el, 'First');
addListItem($el, 'Second');
addListItem($el, 'Third');
import { isPositiveNumber } from '../index';
describe('isPositiveNumber', () => {
test('Returns true if number is positive', () => {
expect(isPositiveNumber(5)).toBe(true);
});
test('Returns false if number is negative', () => {
expect(isPositiveNumber(-5)).toBe(false);
});
import { commaSeparatedStringToArray } from '../index';
describe('commaSeparatedStringToArray', () => {
test('Returns array from comma separated string', () => {
expect(commaSeparatedStringToArray('my,unit,test')).toEqual(['my','unit','test']);
});
test('Throws when non-string passed', () => {
expect(() => {
commaSeparatedStringToArray(5);