Skip to content

Commit

Permalink
Merge pull request #499 from IEvangelist/unitTests
Browse files Browse the repository at this point in the history
Added unit tests for utility functions that I wrote
  • Loading branch information
bharney0 committed Mar 24, 2020
2 parents 801c7ec + 30620f9 commit 9dd85fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Expand Up @@ -29,6 +29,7 @@ suite("Alert Controller", () => {

const spy = chai.spy.on(common, "isMarkdownFileCheck");
insertAlert();
await sleep(300);
expect(spy).to.have.been.called();
});
test("insertContentToEditor - Note", async () => {
Expand All @@ -42,14 +43,14 @@ suite("Alert Controller", () => {
};
const spy = chai.spy.on(common, "insertContentToEditor");
insertAlert();
await sleep(400);
await sleep(500);
expect(spy).to.have.been.called();
});

});

function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms);
return new Promise((r) => {
setTimeout(r, ms);
});
}
13 changes: 6 additions & 7 deletions docs-markdown/src/test/suite/extension.test.ts
@@ -1,21 +1,20 @@
import * as assert from 'assert';
import * as assert from "assert";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import { installedExtensionsCheck, deactivate } from '../../extension';
import { window } from 'vscode';
import { window } from "vscode";
import { deactivate, installedExtensionsCheck } from "../../extension";

suite('Extension Test Suite', () => {
window.showInformationMessage('Start all tests.');
suite("Extension Test Suite", () => {
window.showInformationMessage("Start all tests.");

test('Sample test', () => {
test("Sample test", () => {
deactivate();

installedExtensionsCheck();

assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));


});
});
16 changes: 16 additions & 0 deletions docs-markdown/src/test/suite/helper/utility.test.ts
@@ -0,0 +1,16 @@
import * as chai from "chai";
import * as utility from "../../../helper/utility";

const expect = chai.expect;

suite("Utility helper class", () => {
test("inferLanguageFromFileExtension returns null when not found", () => {
const lang = utility.inferLanguageFromFileExtension(".foobar");
expect(lang).to.be.equal(null);
});

test("inferLanguageFromFileExtension returns correct language when found", () => {
const lang = utility.inferLanguageFromFileExtension(".ts");
expect(lang ? lang.language : "").to.be.equal("TypeScript");
});
});

0 comments on commit 9dd85fa

Please sign in to comment.