diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index ad7e5626a..f68a991c1 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -135,6 +135,7 @@ + time-picker-tests-native.d.ts @@ -1561,7 +1562,7 @@ False - + \ No newline at end of file diff --git a/apps/tests/TKUnit.ts b/apps/tests/TKUnit.ts index 7d86208a1..ef4e4eee2 100644 --- a/apps/tests/TKUnit.ts +++ b/apps/tests/TKUnit.ts @@ -19,14 +19,30 @@ var sdkVersion = parseInt(platform.device.sdkVersion); trace.enable(); +export interface TestInfoEntry { + testFunc: () => void; + instance: Object; + isTest: boolean; + testName: string; + isPassed: boolean; + errorMessage: string; + testTimeout: number; +} + export var write = function write(message: string, type?: number) { //console.log(message); trace.write(message, trace.categories.Test, type); } -var runTest = function (testInfo) { +var runTest = function (testInfo: TestInfoEntry) { try { - testInfo.testFunc(); + if (testInfo.instance) { + testInfo.testFunc.apply(testInfo.instance); + } + else { + testInfo.testFunc(); + } + if (testInfo.isTest) { write("--- [" + testInfo.testName + "] OK", trace.messageType.info); testInfo.isPassed = true; @@ -54,11 +70,11 @@ export interface TestModuleRunResult { failed: Array; } -var testsQueue; +var testsQueue: Array; var defaultTimeout = 5000; // testInfo : {testFunc: func, testName: string, isTest: boolean, isPassed: boolean, errorMessage: string} -function runAsync(testInfo, recursiveIndex, testTimeout?) { +function runAsync(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?: number) { var error; var isDone = false; var handle; @@ -104,22 +120,29 @@ function runAsync(testInfo, recursiveIndex, testTimeout?) { } } - testInfo.testFunc(doneCallback); + if (testInfo.instance) { + testInfo.testFunc.apply(testInfo.instance, [doneCallback]); + } + else { + var func: any = testInfo.testFunc; + func(doneCallback); + } setTimeout(checkFinished, 0); } // tests : Array<{testFunc: func, testName: string, isTest: boolean, isPassed: boolean, errorMessage: string}> -export var runTests = function (tests, recursiveIndex) { +export var runTests = function (tests: Array, recursiveIndex) { testsQueue = tests; var i; for (i = recursiveIndex; i < testsQueue.length; i++) { - if (testsQueue[i].testFunc.length > 0) { - return runAsync(testsQueue[i], i); + var testEntry = testsQueue[i]; + if (testEntry.testFunc.length > 0) { + return runAsync(testEntry, i); } else { - runTest(testsQueue[i]); + runTest(testEntry); } } } @@ -170,6 +193,12 @@ export function assertEqual(actual: any, expected: any, message?: string) { } }; +export function assertNull(actual: any, message?: string) { + if (actual !== null && actual !== undefined) { + throw new Error(message + " Actual: " + actual + " is not null/undefined"); + } +}; + export function assertAreClose(actual: number, expected: number, delta: number, message?: string) { if (isNaN(actual) || Math.abs(actual - expected) > delta) { throw new Error(message + " Numbers are not close enough. Actual: " + actual + " Expected: " + expected + " Delta: " + delta); diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index be7855725..f9d8b418c 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -20,7 +20,7 @@ class MyTraceWriter implements trace.TraceWriter { trace.addWriter(new MyTraceWriter()); trace.enable(); -trace.setCategories(trace.categories.Test + "," + trace.categories.Error); +trace.addCategories(trace.categories.Test + "," + trace.categories.Error); var textView = new textViewModule.TextView(); textView.editable = false; diff --git a/apps/tests/app/testRunnerPage.ts b/apps/tests/app/testRunnerPage.ts index 9e571f4eb..5e9986261 100644 --- a/apps/tests/app/testRunnerPage.ts +++ b/apps/tests/app/testRunnerPage.ts @@ -4,7 +4,7 @@ import bm = require("ui/button"); import listViewDef = require("ui/list-view"); import trace = require("trace"); trace.enable(); -trace.setCategories(trace.categories.Test + "," + trace.categories.Error); +trace.addCategories(trace.categories.Test + "," + trace.categories.Error); export function createPage() { var data: string[] = [""]; diff --git a/apps/tests/layouts/dock-layout-tests.ts b/apps/tests/layouts/dock-layout-tests.ts index a352e7161..727e9ab49 100644 --- a/apps/tests/layouts/dock-layout-tests.ts +++ b/apps/tests/layouts/dock-layout-tests.ts @@ -20,8 +20,8 @@ import dockModule = require("ui/layouts/dock-layout"); //