Skip to content

Commit

Permalink
Update uncovered tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Dec 26, 2017
1 parent 1d3c3f6 commit 709ab28
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 53 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
},
"homepage": "https://github.com/kokororin/honoka#readme",
"dependencies": {
"array-reduce": "^0.0.0",
"foreach": "^2.0.5",
"node-fetch": "^1.7.2",
"querystring": "^0.2.0",
"whatwg-fetch": "^2.0.3"
Expand Down
3 changes: 1 addition & 2 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { forEach } from './utils';

import forEach from 'foreach';
// honoka default options
const defaults = {
baseURL: '',
Expand Down
6 changes: 3 additions & 3 deletions src/honoka.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import forEach from 'foreach';
import reduce from 'array-reduce';
import qsEncode from 'querystring/encode';
import {
trimStart,
Expand All @@ -9,9 +11,7 @@ import {
isArray,
isString,
isFormData,
isNode,
forEach,
reduce
isNode
} from './utils';
import defaults from './defaults';
import methods from './methods';
Expand Down
1 change: 0 additions & 1 deletion src/interceptors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// honoka interceptors injections
const interceptorContainer = [];

function register(interceptor) {
Expand Down
53 changes: 7 additions & 46 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import forEach from 'foreach';
import methods from './methods';

const spaceChars = ' \\s\u00A0';
Expand All @@ -16,7 +17,6 @@ export function trimEnd(str, charlist = spaceChars) {
}

const toString = Object.prototype.toString;
const hasOwn = Object.prototype.hasOwnProperty;

export function isObject(value) {
return value !== null && typeof value === 'object';
Expand All @@ -35,53 +35,14 @@ export function isFormData(value) {
}

export function isNode() {
return !!(
if (
typeof global.process !== 'undefined' &&
global.process.versions &&
global.process.versions.node
);
}

export function forEach(object, fn, context) {
if (toString.call(fn) !== '[object Function]') {
throw new TypeError('iterator must be a function');
}

const l = object.length;
if (l === +l) {
for (let i = 0; i < l; i++) {
fn.call(context, object[i], i, object);
}
} else {
for (const k in object) {
if (Object.prototype.hasOwnProperty.call(object, k)) {
fn.call(context, object[k], k, object);
}
}
}
}

export function reduce(array, fn, initialValue) {
let hasAcc = arguments.length >= 3;
if (hasAcc && array.reduce) {
return array.reduce(fn, initialValue);
}
if (array.reduce) {
return array.reduce(fn);
}

for (let i = 0; i < array.length; i++) {
if (!hasOwn.call(array, i)) {
continue;
}
if (!hasAcc) {
initialValue = array[i];
hasAcc = true;
continue;
}
initialValue = fn(initialValue, array[i], i);
/* istanbul ignore next */ global.process.versions &&
/* istanbul ignore next */ global.process.versions.node
) {
/* istanbul ignore next */ return true;
}
return initialValue;
return false;
}

export function isAbsoluteURL(url) {
Expand Down
12 changes: 12 additions & 0 deletions test/honokaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ describe('honoka', () => {
expect(data instanceof ArrayBuffer).to.equal(true);
});

it('honoka() should throw Error when dataType is "buffer"', async () => {
let err;
try {
await honoka(`${EXPRESS_BASE_URL}/with/blob`, { dataType: 'buffer' });
} catch (e) {
err = e;
}
expect(() => {
throw err;
}).to.throw(/"buffer" is not supported in browser/);
});

it('honoka.post() should post JSON correctly', async () => {
const data = await honoka.post(`${EXPRESS_BASE_URL}/post/param`, {
headers: {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (process.env.NODE_ENV === 'test') {
config.module.rules.push({
test: /\.(js|jsx)$/,
enforce: 'post',
exclude: /node_modules|test/,
exclude: /node_modules|test|src\/interceptors\.js/,
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ array-includes@^3.0.3:
define-properties "^1.1.2"
es-abstract "^1.7.0"

array-reduce@^0.0.0:
version "0.0.0"
resolved "https://registry.npmjs.org/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b"

array-slice@^0.2.3:
version "0.2.3"
resolved "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz#dd3cfb80ed7973a75117cdac69b0b99ec86186f5"
Expand Down

0 comments on commit 709ab28

Please sign in to comment.