Skip to content

Commit

Permalink
test: add cases
Browse files Browse the repository at this point in the history
  • Loading branch information
YanxinTang committed Aug 2, 2020
1 parent 42ef154 commit 1c8b28a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import components from '../../components.json';

describe('import components demand', () => {
describe('import components', () => {
const componentMethod = jest.fn();
test('import components on damand', async () => {
const _Vue = { component: componentMethod };
const _Vue = { component: componentMethod };
beforeEach(() => {
componentMethod.mockClear();
});

test('use components on damand', async () => {
for (const path of Object.values(components)) {
const { default: Component } = await import(path);
// eslint-disable-next-line
Expand All @@ -14,4 +17,10 @@ describe('import components demand', () => {
expect(componentMethod).toHaveBeenCalledWith(Component.name, Component);
}
});

test('use library', async () => {
const { default: libInstall } = await import('@/index');
libInstall(_Vue);
expect(componentMethod).toHaveBeenCalledTimes(Object.keys(components).length);
});
});
30 changes: 30 additions & 0 deletions test/unit/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as utils from '@/utils';

describe('utils', () => {
test('isValidGridValue', () => {
const valid = Array.from(new Array(13), (x, i) => i);
const invalid = [-1, 13];
valid.forEach(value => {
expect(utils.isValidGridValue(value)).toBe(true);
});
invalid.forEach(value => {
expect(utils.isValidGridValue(value)).toBe(false);
});
});

test('isBoolean', () => {
expect(utils.isBoolean(true)).toBe(true);
expect(utils.isBoolean('')).toBe(false);
});

test('isArray', () => {
expect(utils.isArray([])).toBe(true);
expect(utils.isArray('')).toBe(false);
});

test('isUndefined', () => {
expect(utils.isUndefined(undefined)).toBe(true);
expect(utils.isUndefined(null)).toBe(false);
expect(utils.isUndefined('')).toBe(false);
});
});

0 comments on commit 1c8b28a

Please sign in to comment.