Skip to content

Commit

Permalink
Added utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patw0929 committed Apr 7, 2016
1 parent 4066506 commit d90745c
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tests/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,45 @@ import { assert } from 'chai';

describe('utils', () => {
it('arraysEqual', () => {
const a = ['1', '2', '3'];
const b = ['3', '1', '2'];
let a = [1, 2, 3];
let b = [1, 2, 3];
assert(utils.arraysEqual(a, b) === true);

b = null;
assert(utils.arraysEqual(a, b) === false);

a = ['1', '2', '3'];
b = ['3', '1', '2'];
assert(utils.arraysEqual(a, b) === false);
});

it('shallowEquals', () => {
const a = {
let a = [1, 2, 3];
let b = [1, 2, 3];
assert(utils.shallowEquals(a, b) === true);

a = {
x: ['1', '2', '3'],
y: 'abc',
};
const b = {
b = {
x: ['1', '2', '3'],
y: 'abc',
};
assert(utils.shallowEquals(a, b) === true);

a = {
a: 1,
b: 2,
};
b = a;
assert(utils.shallowEquals(a, b) === true);
});

it('trim', () => {
const str = ' Hello World ';
assert(utils.trim(undefined) === '');

const str = ' Hello World ';
assert(utils.trim(str) === 'Hello World');
});

Expand All @@ -44,8 +61,10 @@ describe('utils', () => {
</body></html>`;
const doc = jsdom.jsdom(DEFAULT_HTML);
const bListItem = doc.querySelector('.b');

assert(utils.retrieveLiIndex(bListItem) === 1);

const otherListItem = doc.querySelector('.z');
assert(utils.retrieveLiIndex(otherListItem) === -1);
});

it('getNumeric', () => {
Expand Down Expand Up @@ -83,6 +102,9 @@ describe('utils', () => {
areaCodes: null,
};
assert.deepEqual(utils.getCountryData('tw'), result);

assert(utils.getCountryData('zz', true) === null);
assert.deepEqual(utils.getCountryData('zz', false, (country) => `${country}!!`), {});
});

it('hasClass', () => {
Expand Down

0 comments on commit d90745c

Please sign in to comment.