Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for utility functions that I wrote #499

Merged
merged 2 commits into from Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
});
});