Test cleanup and fixes [g-h]
This commit is contained in:
@ -1,14 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const gcd = require('./gcd.js');
|
||||
|
||||
|
||||
test('gcd is a Function', () => {
|
||||
test('gcd is a Function', () => {
|
||||
expect(gcd).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
|
||||
expect(gcd(8, 36)).toBe(4)
|
||||
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
|
||||
expect(gcd(8, 36)).toBe(4);
|
||||
});
|
||||
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
|
||||
expect(gcd(...[12, 8, 32])).toEqual(4)
|
||||
});
|
||||
|
||||
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
|
||||
expect(gcd(...[12, 8, 32])).toEqual(4);
|
||||
});
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const geometricProgression = require('./geometricProgression.js');
|
||||
|
||||
|
||||
test('geometricProgression is a Function', () => {
|
||||
test('geometricProgression is a Function', () => {
|
||||
expect(geometricProgression).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256), [1, 2, 4, 8, 16, 32, 64, 128).toEqual(256])
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256)).toEqual([1, 2, 4, 8, 16, 32, 64, 128, 256])
|
||||
});
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256, 3), [3, 6, 12, 24, 48, 96).toEqual(192])
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256, 3)).toEqual([3, 6, 12, 24, 48, 96, 192])
|
||||
});
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256, 1, 4), [1, 4, 16, 64).toEqual(256])
|
||||
test('Initializes an array containing the numbers in the specified range', () => {
|
||||
expect(geometricProgression(256, 1, 4)).toEqual([1, 4, 16, 64, 256])
|
||||
});
|
||||
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const get = require('./get.js');
|
||||
|
||||
|
||||
test('get is a Function', () => {
|
||||
test('get is a Function', () => {
|
||||
expect(get).toBeInstanceOf(Function);
|
||||
});
|
||||
const obj = { selector: { to: { val: 'val to get' } } };
|
||||
test('Retrieve a property indicated by the selector from an object.', () => {
|
||||
const obj = { selector: { to: { val: 'val to get' } } };
|
||||
test('Retrieve a property indicated by the selector from an object.', () => {
|
||||
expect(get(obj, 'selector.to.val')).toEqual(['val to get'])
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const getColonTimeFromDate = require('./getColonTimeFromDate.js');
|
||||
|
||||
|
||||
test('getColonTimeFromDate is a Function', () => {
|
||||
test('getColonTimeFromDate is a Function', () => {
|
||||
expect(getColonTimeFromDate).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const getDaysDiffBetweenDates = require('./getDaysDiffBetweenDates.js');
|
||||
|
||||
|
||||
test('getDaysDiffBetweenDates is a Function', () => {
|
||||
test('getDaysDiffBetweenDates is a Function', () => {
|
||||
expect(getDaysDiffBetweenDates).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns the difference in days between two dates', () => {
|
||||
expect(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22'))).toBe(9)
|
||||
test('Returns the difference in days between two dates', () => {
|
||||
expect(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22'))).toBe(9);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const getMeridiemSuffixOfInteger = require('./getMeridiemSuffixOfInteger.js');
|
||||
|
||||
|
||||
test('getMeridiemSuffixOfInteger is a Function', () => {
|
||||
test('getMeridiemSuffixOfInteger is a Function', () => {
|
||||
expect(getMeridiemSuffixOfInteger).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const getScrollPosition = require('./getScrollPosition.js');
|
||||
|
||||
|
||||
test('getScrollPosition is a Function', () => {
|
||||
test('getScrollPosition is a Function', () => {
|
||||
expect(getScrollPosition).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const getStyle = require('./getStyle.js');
|
||||
|
||||
|
||||
test('getStyle is a Function', () => {
|
||||
test('getStyle is a Function', () => {
|
||||
expect(getStyle).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const getType = require('./getType.js');
|
||||
|
||||
|
||||
test('getType is a Function', () => {
|
||||
test('getType is a Function', () => {
|
||||
expect(getType).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns the native type of a value', () => {
|
||||
expect(getType(new Set([1, 2, 3]))).toBe('set')
|
||||
test('Returns the native type of a value', () => {
|
||||
expect(getType(new Set([1, 2, 3]))).toBe('set');
|
||||
});
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const getURLParameters = require('./getURLParameters.js');
|
||||
|
||||
|
||||
test('getURLParameters is a Function', () => {
|
||||
test('getURLParameters is a Function', () => {
|
||||
expect(getURLParameters).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(getURLParameters('http:
|
||||
|
||||
test('Returns an object containing the parameters of the current URL', () => {
|
||||
expect(getURLParameters(getURLParameters('http://url.com/page?name=Adam&surname=Smith')).toEqual({name: 'Adam', surname: 'Smith'});
|
||||
});
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const groupBy = require('./groupBy.js');
|
||||
|
||||
|
||||
test('groupBy is a Function', () => {
|
||||
test('groupBy is a Function', () => {
|
||||
expect(groupBy).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy([6.1, 4.2, 6.3], Math.floor), {4: [4.2], 6: [6.1).toEqual(6.3]})
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy([6.1, 4.2, 6.3], Math.floor)).toEqual({4: [4.2], 6: [6.1, 6.3]});
|
||||
});
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy(['one', 'two', 'three'], 'length'), {3: ['one', 'two']).toEqual(5: ['three']})
|
||||
});
|
||||
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy(['one', 'two', 'three'], 'length')).toEqual({3: ['one', 'two'], 5: ['three']});
|
||||
});
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const hammingDistance = require('./hammingDistance.js');
|
||||
|
||||
|
||||
test('hammingDistance is a Function', () => {
|
||||
test('hammingDistance is a Function', () => {
|
||||
expect(hammingDistance).toBeInstanceOf(Function);
|
||||
});
|
||||
test('retuns hamming disance between 2 values', () => {
|
||||
expect(hammingDistance(2, 3)).toBe(1)
|
||||
test('retuns hamming disance between 2 values', () => {
|
||||
expect(hammingDistance(2, 3)).toBe(1);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const hasClass = require('./hasClass.js');
|
||||
|
||||
|
||||
test('hasClass is a Function', () => {
|
||||
test('hasClass is a Function', () => {
|
||||
expect(hasClass).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const hasFlags = require('./hasFlags.js');
|
||||
|
||||
|
||||
test('hasFlags is a Function', () => {
|
||||
test('hasFlags is a Function', () => {
|
||||
expect(hasFlags).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const hashBrowser = require('./hashBrowser.js');
|
||||
|
||||
|
||||
test('hashBrowser is a Function', () => {
|
||||
test('hashBrowser is a Function', () => {
|
||||
expect(hashBrowser).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const hashNode = require('./hashNode.js');
|
||||
|
||||
|
||||
test('hashNode is a Function', () => {
|
||||
test('hashNode is a Function', () => {
|
||||
expect(hashNode).toBeInstanceOf(Function);
|
||||
});
|
||||
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v => t.equal(v, '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393', 'Produces the appropriate hash'));
|
||||
|
||||
|
||||
test('Produces the appropriate hash', () => {
|
||||
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v => expect(v).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'));
|
||||
});
|
||||
|
||||
@ -1,30 +1,33 @@
|
||||
const expect = require('expect');
|
||||
const head = require('./head.js');
|
||||
|
||||
|
||||
test('head is a Function', () => {
|
||||
test('head is a Function', () => {
|
||||
expect(head).toBeInstanceOf(Function);
|
||||
});
|
||||
test('head({ a: 1234}) returns undefined', () => {
|
||||
test('head({ a: 1234}) returns undefined', () => {
|
||||
expect(head({ a: 1234}) === undefined).toBeTruthy();
|
||||
});
|
||||
test('head([1, 2, 3]) returns 1', () => {
|
||||
expect(head([1, 2, 3])).toBe(1)
|
||||
test('head([1, 2, 3]) returns 1', () => {
|
||||
expect(head([1, 2, 3])).toBe(1);
|
||||
});
|
||||
test('head({ 0: false}) returns false', () => {
|
||||
expect(head({ 0: false}), false).toBe()
|
||||
test('head({ 0: false}) returns false', () => {
|
||||
expect(head({ 0: false})).toBeFalsy();
|
||||
});
|
||||
test('head(String) returns S', () => {
|
||||
expect(head('String'), 'S').toBe()
|
||||
test('head(String) returns S', () => {
|
||||
expect(head('String')).toBe('S');
|
||||
});
|
||||
t.throws(() => head(null), 'head(null) throws an Error');
|
||||
t.throws(() => head(undefined), 'head(undefined) throws an Error');
|
||||
t.throws(() => head(), 'head() throws an Error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
|
||||
let end = new Date().getTime();
|
||||
test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
|
||||
test('head(null) throws an Error', () => {
|
||||
expect(head(null)).toThrow();
|
||||
});
|
||||
test('head(undefined) throws an Error', () => {
|
||||
expect(head(undefined)).toThrow();
|
||||
});
|
||||
test('head() throws an Error', () => {
|
||||
expect(head()).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
|
||||
let end = new Date().getTime();
|
||||
test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const hexToRGB = require('./hexToRGB.js');
|
||||
|
||||
|
||||
test('hexToRGB is a Function', () => {
|
||||
test('hexToRGB is a Function', () => {
|
||||
expect(hexToRGB).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('#27ae60ff'), 'rgba(39, 174, 96).toBe(255)')
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('#27ae60ff')).toBe('rgba(39, 174, 96, 255)');
|
||||
});
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('27ae60'), 'rgb(39, 174).toBe(96)')
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('27ae60')).toBe('rgb(39, 174, 96)');
|
||||
});
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('#fff'), 'rgb(255, 255).toBe(255)')
|
||||
test('Converts a color code to a rgb() or rgba() string', () => {
|
||||
expect(hexToRGB('#fff')).toBe('rgb(255, 255, 255)');
|
||||
});
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const hide = require('./hide.js');
|
||||
|
||||
|
||||
test('hide is a Function', () => {
|
||||
test('hide is a Function', () => {
|
||||
expect(hide).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const howManyTimes = require('./howManyTimes.js');
|
||||
|
||||
|
||||
test('howManyTimes is a Function', () => {
|
||||
test('howManyTimes is a Function', () => {
|
||||
expect(howManyTimes).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const httpDelete = require('./httpDelete.js');
|
||||
|
||||
|
||||
test('httpDelete is a Function', () => {
|
||||
test('httpDelete is a Function', () => {
|
||||
expect(httpDelete).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -7,21 +7,20 @@ const httpGet = (url, callback, err = console.error) => {
|
||||
request.send();
|
||||
};
|
||||
|
||||
|
||||
test('httpGet is a Function', () => {
|
||||
test('httpGet is a Function', () => {
|
||||
expect(httpGet).toBeInstanceOf(Function);
|
||||
});
|
||||
httpGet('https:
|
||||
t.deepEqual(JSON.parse(response), {
|
||||
userId: 1,
|
||||
id: 1,
|
||||
title:
|
||||
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
|
||||
body:
|
||||
'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto',
|
||||
}, 'Sends a GET request');
|
||||
|
||||
|
||||
test('Sends a GET request', () => {
|
||||
httpGet('https://jsonplaceholder.typicode.com/posts/1', response => {
|
||||
expect(JSON.parse(response)),toEqual({
|
||||
userId: 1,
|
||||
id: 1,
|
||||
title:
|
||||
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
|
||||
body:
|
||||
'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto',
|
||||
});
|
||||
});
|
||||
|
||||
var Url = require("url");
|
||||
var spawn = require("child_process").spawn;
|
||||
@ -289,7 +288,7 @@ XMLHttpRequest = function() {
|
||||
self.responseText = data;
|
||||
setState(self.DONE);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
try {
|
||||
this.responseText = fs.readFileSync(url.pathname, "utf8");
|
||||
@ -377,18 +376,18 @@ XMLHttpRequest = function() {
|
||||
if (sendFlag) {
|
||||
setState(self.LOADING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
response.on("end", function() {
|
||||
if (sendFlag) {
|
||||
setState(self.DONE);
|
||||
sendFlag = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
response.on("error", function(error) {
|
||||
self.handleError(error);
|
||||
|
||||
|
||||
};
|
||||
var errorHandler = function errorHandler(error) {
|
||||
self.handleError(error);
|
||||
@ -502,7 +501,7 @@ XMLHttpRequest = function() {
|
||||
if (event in listeners) {
|
||||
listeners[event] = listeners[event].filter(function(ev) {
|
||||
return ev !== callback;
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -8,20 +8,19 @@ const httpPost = (url, data, callback, err = console.error) => {
|
||||
request.send(data);
|
||||
};
|
||||
|
||||
test('httpPost is a Function', () => {
|
||||
test('httpPost is a Function', () => {
|
||||
expect(httpPost).toBeInstanceOf(Function);
|
||||
});
|
||||
const data = {
|
||||
title: 'foo',
|
||||
body: 'bar',
|
||||
userId: 1
|
||||
};
|
||||
httpPost('https:
|
||||
test('Sends a POST request', () => {
|
||||
expect(JSON.parse(response).id, 101).toEqual()
|
||||
const data = {
|
||||
title: 'foo',
|
||||
body: 'bar',
|
||||
userId: 1
|
||||
};
|
||||
test('Sends a POST request', () => {
|
||||
httpPost('https://jsonplaceholder.typicode.com/posts', JSON.stringify(data), response => {
|
||||
expect(JSON.parse(response).id).toEqual(101);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
var Url = require("url");
|
||||
var spawn = require("child_process").spawn;
|
||||
@ -289,7 +288,7 @@ XMLHttpRequest = function() {
|
||||
self.responseText = data;
|
||||
setState(self.DONE);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
try {
|
||||
this.responseText = fs.readFileSync(url.pathname, "utf8");
|
||||
@ -377,18 +376,18 @@ XMLHttpRequest = function() {
|
||||
if (sendFlag) {
|
||||
setState(self.LOADING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
response.on("end", function() {
|
||||
if (sendFlag) {
|
||||
setState(self.DONE);
|
||||
sendFlag = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
response.on("error", function(error) {
|
||||
self.handleError(error);
|
||||
|
||||
|
||||
};
|
||||
var errorHandler = function errorHandler(error) {
|
||||
self.handleError(error);
|
||||
@ -502,7 +501,7 @@ XMLHttpRequest = function() {
|
||||
if (event in listeners) {
|
||||
listeners[event] = listeners[event].filter(function(ev) {
|
||||
return ev !== callback;
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const httpPut = require('./httpPut.js');
|
||||
|
||||
|
||||
test('httpPut is a Function', () => {
|
||||
test('httpPut is a Function', () => {
|
||||
expect(httpPut).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const httpsRedirect = require('./httpsRedirect.js');
|
||||
|
||||
|
||||
test('httpsRedirect is a Function', () => {
|
||||
test('httpsRedirect is a Function', () => {
|
||||
expect(httpsRedirect).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const hz = require('./hz.js');
|
||||
|
||||
|
||||
test('hz is a Function', () => {
|
||||
test('hz is a Function', () => {
|
||||
expect(hz).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user