Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jiming committed Mar 3, 2022
1 parent ff002d7 commit b952acd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/common/__tests__/dom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { findParentByClassName, getPositionByPlacement } from '../dom';
import {
findParentByClassName,
getPositionByPlacement,
getElementClientCenter,
} from '../dom';

describe('Test functions in dom.ts', () => {
test('The getPositionByPlacement function', () => {
Expand Down Expand Up @@ -47,4 +51,23 @@ describe('Test functions in dom.ts', () => {
findParentByClassName(1, 'test');
}).toThrowError();
});

test('The getElementClientCenter function', () => {
const elem = document.createElement('div');
const domRect = {
x: 10,
y: 10,
width: 10,
height: 10,
top: 10,
right: 10,
bottom: 10,
left: 10,
} as DOMRect;
elem.getBoundingClientRect = jest.fn(() => domRect);

const center = getElementClientCenter(elem);
expect(center.x).toEqual(15);
expect(center.y).toEqual(15);
});
});
12 changes: 11 additions & 1 deletion src/common/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { normalizeFlattedObject, colorLightOrDark } from '../utils';
import {
normalizeFlattedObject,
colorLightOrDark,
cloneInstance,
} from '../utils';

describe('Test Utils', () => {
test('The normalizeFlattedObject function', () => {
Expand Down Expand Up @@ -40,4 +44,10 @@ describe('Test Utils', () => {
expect(colorLightOrDark('#000')).toBe('dark');
expect(colorLightOrDark('rgb(255,255,255)')).toBe('light');
});

test('The cloneInstance function', () => {
const obj1 = { name: 'test' };
const obj2 = cloneInstance(obj1);
expect(obj1.name).toEqual(obj2.name);
});
});

0 comments on commit b952acd

Please sign in to comment.