Check leaks in Mocha

This commit is contained in:
Evan Hahn 2021-01-11 14:17:09 -06:00 committed by GitHub
parent 7543d8b60d
commit dc918aea1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 38 deletions

3
.mocharc.json Normal file
View File

@ -0,0 +1,3 @@
{
"checkLeaks": true
}

View File

@ -7,9 +7,6 @@ import sinon from 'sinon';
import { EmojiCompletion } from '../../../quill/emoji/completion'; import { EmojiCompletion } from '../../../quill/emoji/completion';
import { EmojiData } from '../../../components/emoji/lib'; import { EmojiData } from '../../../components/emoji/lib';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalAsAny = global as any;
describe('emojiCompletion', () => { describe('emojiCompletion', () => {
let emojiCompletion: EmojiCompletion; let emojiCompletion: EmojiCompletion;
const mockOnPickEmoji = sinon.spy(); const mockOnPickEmoji = sinon.spy();
@ -18,14 +15,6 @@ describe('emojiCompletion', () => {
let mockQuill: any; let mockQuill: any;
beforeEach(function beforeEach() { beforeEach(function beforeEach() {
this.oldDocument = globalAsAny.document;
globalAsAny.document = {
body: {
appendChild: () => null,
},
createElement: () => null,
};
mockQuill = { mockQuill = {
getLeaf: sinon.stub(), getLeaf: sinon.stub(),
getSelection: sinon.stub(), getSelection: sinon.stub(),
@ -55,12 +44,6 @@ describe('emojiCompletion', () => {
mockOnPickEmoji.resetHistory(); mockOnPickEmoji.resetHistory();
mockSetEmojiPickerElement.resetHistory(); mockSetEmojiPickerElement.resetHistory();
(emojiCompletion.render as sinon.SinonStub).resetHistory(); (emojiCompletion.render as sinon.SinonStub).resetHistory();
if (this.oldDocument === undefined) {
delete globalAsAny.document;
} else {
globalAsAny.document = this.oldDocument;
}
}); });
describe('getCurrentLeafTextPartitions', () => { describe('getCurrentLeafTextPartitions', () => {

View File

@ -52,20 +52,6 @@ const members: Array<ConversationType> = [
me, me,
]; ];
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface Global {
document: {
body: {
appendChild: unknown;
};
createElement: unknown;
};
}
}
}
describe('MentionCompletion', () => { describe('MentionCompletion', () => {
const mockSetMentionPickerElement = sinon.spy(); const mockSetMentionPickerElement = sinon.spy();
@ -78,13 +64,6 @@ describe('MentionCompletion', () => {
let mentionCompletion: MentionCompletion; let mentionCompletion: MentionCompletion;
beforeEach(function beforeEach() { beforeEach(function beforeEach() {
global.document = {
body: {
appendChild: sinon.spy(),
},
createElement: sinon.spy(),
};
const memberRepositoryRef: MutableRefObject<MemberRepository> = { const memberRepositoryRef: MutableRefObject<MemberRepository> = {
current: new MemberRepository(members), current: new MemberRepository(members),
}; };