Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Oct 14, 2020
1 parent 7d50925 commit 126252d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions projects/cdk/services/test/resize.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ describe('TuiResizeService', () => {
});
});

afterEach(() => {
document.body.removeChild(element);
});

it('emits default first value', done => {
const resize$ = TestBed.get(TuiResizeService);

Expand Down
6 changes: 6 additions & 0 deletions projects/cdk/utils/dom/test/get-closest-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('getClosestElement', () => {
document.body.appendChild(div);

expect(getClosestElement(element, 'div')).toEqual(div);

document.body.removeChild(element);
document.body.removeChild(div);
});

it('fallback works without closest and matches element', () => {
Expand All @@ -25,6 +28,8 @@ describe('getClosestElement', () => {
expect(getClosestElement(element, 'div')).toEqual(div);

Element.prototype.closest = savedCLosest;
document.body.removeChild(element);
document.body.removeChild(div);
});

it('fallback works without closest and with nested element', () => {
Expand All @@ -39,5 +44,6 @@ describe('getClosestElement', () => {
expect(getClosestElement(div, 'img')).toEqual(null);

Element.prototype.closest = savedCLosest;
document.body.removeChild(div);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ describe('getDocumentOrShadowRoot', () => {
expect(getDocumentOrShadowRoot(element)).toEqual(
element.getRootNode() as Document,
);

document.body.removeChild(element);
});
});
6 changes: 6 additions & 0 deletions projects/cdk/utils/dom/test/is-node-in.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe('isNodeIn', () => {
document.body.appendChild(div);

expect(isNodeIn(div, 'div')).toEqual(true);

document.body.removeChild(div);
});

it('class selector', () => {
Expand All @@ -17,6 +19,8 @@ describe('isNodeIn', () => {
document.body.appendChild(div);

expect(isNodeIn(div, '.hello')).toEqual(true);

document.body.removeChild(div);
});

it('works with text nodes', () => {
Expand All @@ -28,5 +32,7 @@ describe('isNodeIn', () => {
document.body.appendChild(p);

expect(isNodeIn(textNode, 'p')).toEqual(true);

document.body.removeChild(p);
});
});
8 changes: 4 additions & 4 deletions projects/cdk/utils/focus/tests/blur-native-focused.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ describe('blurNativeFocused', () => {
let element: HTMLInputElement;

beforeEach(() => {
if (element) {
document.body.removeChild(element);
}

element = document.createElement('input');
document.body.appendChild(element);
setNativeFocused(element, true);
});

afterAll(() => {
document.body.removeChild(element);
});

it('Element is focused', () => {
expect(document.activeElement).toBe(element);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe('getClosestKeyboardFocusable', () => {
document.body.appendChild(root);

expect(getClosestKeyboardFocusable(divElement, true, root)).toBe(buttonElement);

document.body.removeChild(root);
});

it('returns closest focusable if there is towards', () => {
Expand All @@ -30,6 +32,8 @@ describe('getClosestKeyboardFocusable', () => {
document.body.appendChild(root);

expect(getClosestKeyboardFocusable(divElement, false, root)).toBe(buttonElement);

document.body.removeChild(root);
});

it('returns null if there is no focusable elements', () => {
Expand All @@ -40,5 +44,7 @@ describe('getClosestKeyboardFocusable', () => {
document.body.appendChild(root);

expect(getClosestKeyboardFocusable(divElement, undefined, root)).toBe(null);

document.body.removeChild(root);
});
});
4 changes: 4 additions & 0 deletions projects/cdk/utils/focus/tests/get-native-focused.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('getNativeFocused', () => {
buttonElement.focus();

expect(getNativeFocused(document)).toBe(buttonElement);

document.body.removeChild(buttonElement);
});

it('returns element from shadowRoot', () => {
Expand All @@ -22,5 +24,7 @@ describe('getNativeFocused', () => {
buttonElement.focus();

expect(getNativeFocused(document)).toBe(buttonElement);

document.body.removeChild(div);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {isNativeFocusedIn} from '../is-native-focused-in';

describe('isNativeFocusedIn', () => {
it('element is not focused in', () => {
const element = document.createElement('buton');
const element = document.createElement('button');

expect(isNativeFocusedIn(element)).toEqual(false);
});
Expand Down
3 changes: 3 additions & 0 deletions projects/cdk/utils/focus/tests/move-focus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ describe('move focus', () => {
moveFocus(0, arr, 1);

expect(document.activeElement).toEqual(second);

document.body.removeChild(first);
document.body.removeChild(second);
});
});
8 changes: 4 additions & 4 deletions projects/cdk/utils/focus/tests/set-native-focused.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ describe('setNativeFocused', () => {
let top: number;

beforeEach(() => {
if (element) {
document.body.removeChild(element);
}

element = document.createElement('input');
element.style.marginTop = '200vh';
document.body.scrollTop = 0;
document.body.appendChild(element);
top = element.getBoundingClientRect().top;
});

afterEach(() => {
document.body.removeChild(element);
});

it('Element is not focused', () => {
expect(document.activeElement).not.toBe(element);
});
Expand Down

0 comments on commit 126252d

Please sign in to comment.