| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,26 +1,32 @@ | |||
| 1 | 1 | import { path } from "tns-core-modules/file-system"; | |
| 2 | 2 | import { loadPage } from "tns-core-modules/ui/builder"; | |
| 3 | - import { assertEqual, assertNull } from "../../TKUnit"; | ||
| 3 | + import { assertEqual, assertNull, assertThrows } from "../../TKUnit"; | ||
| 4 | 4 | ||
| 5 | 5 | const COMPONENT_MODULE = "component-module"; | |
| 6 | + const MISSING_MODULE = "missing-module"; | ||
| 6 | 7 | const LABEL = "label"; | |
| 7 | 8 | ||
| 8 | - function getViewComponent() { | ||
| 9 | - const moduleNamePath = path.join(__dirname, COMPONENT_MODULE); | ||
| 10 | - const fileName = path.join(__dirname, `${COMPONENT_MODULE}.xml`); | ||
| 9 | + function getViewComponent(componentModule: string) { | ||
| 10 | + const moduleNamePath = path.join(__dirname, componentModule); | ||
| 11 | + const fileName = path.join(__dirname, `${componentModule}.xml`); | ||
| 11 | 12 | const view = loadPage(moduleNamePath, fileName); | |
| 12 | 13 | return view; | |
| 13 | 14 | } | |
| 14 | 15 | ||
| 15 | 16 | export function test_view_is_module_root_component() { | |
| 16 | - const view = getViewComponent(); | ||
| 17 | + const view = getViewComponent(COMPONENT_MODULE); | ||
| 17 | 18 | const actualModule = view._moduleName; | |
| 18 | 19 | assertEqual(actualModule, COMPONENT_MODULE, `View<${view}> is NOT root component of module <${COMPONENT_MODULE}>.`); | |
| 19 | 20 | } | |
| 20 | 21 | ||
| 21 | 22 | export function test_view_is_NOT_module_root_component() { | |
| 22 | - const view = getViewComponent(); | ||
| 23 | + const view = getViewComponent(COMPONENT_MODULE); | ||
| 23 | 24 | const nestedView = view.getViewById(`${LABEL}`); | |
| 24 | 25 | const undefinedModule = nestedView._moduleName; | |
| 25 | 26 | assertNull(undefinedModule, `View<${nestedView}> should NOT be a root component of a module.`); | |
| 26 | 27 | } | |
| 28 | + | ||
| 29 | + export function test_load_component_from_missing_module_throws() { | ||
| 30 | + assertThrows(() => getViewComponent(MISSING_MODULE), | ||
| 31 | + "Loading component from a missing module SHOULD throw an error.") | ||
| 32 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,9 +35,10 @@ export function test_parse_IsDefined() { | |||
| 35 | 35 | TKUnit.assertTrue(types.isFunction(builder.parse), "ui/builder should have parse method!"); | |
| 36 | 36 | }; | |
| 37 | 37 | ||
| 38 | - export function test_load_ShouldNotCrashWithInvalidFileName() { | ||
| 39 | - var v = builder.load(fs.path.join(__dirname, "mainPage1.xml")); | ||
| 40 | - TKUnit.assertTrue(types.isUndefined(v), "Expected result: undefined; Actual result: " + v + ";"); | ||
| 38 | + export function test_load_ShouldThrowWithInvalidFileName() { | ||
| 39 | + let fileName = fs.path.join(__dirname, "invalid-page.xml"); | ||
| 40 | + TKUnit.assertThrows(() => builder.load(fileName), | ||
| 41 | + "Loading component from a missing module SHOULD throw an error."); | ||
| 41 | 42 | }; | |
| 42 | 43 | ||
| 43 | 44 | export function test_load_ShouldNotCrashWithoutExports() { | |
@@ -300,7 +301,7 @@ export function test_parse_ShouldSetCanvasAttachedProperties() { | |||
| 300 | 301 | var child = absLayout.getChildAt(0); | |
| 301 | 302 | ||
| 302 | 303 | var left = absoluteLayoutModule.AbsoluteLayout.getLeft(child); | |
| 303 | - | ||
| 304 | + | ||
| 304 | 305 | TKUnit.assert(Length.equals(left, Length.parse("1")), `Expected result for canvas left: 1; Actual result: ${(<any>left).value};`) | |
| 305 | 306 | ||
| 306 | 307 | var top = absoluteLayoutModule.AbsoluteLayout.getTop(child); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,9 @@ export function load(pathOrOptions: string | LoadOptions, context?: any): View { | |||
| 60 | 60 | export function loadPage(moduleNamePath: string, fileName: string, context?: any): View { | |
| 61 | 61 | const componentModule = loadInternal(fileName, context, moduleNamePath); | |
| 62 | 62 | const componentView = componentModule && componentModule.component; | |
| 63 | - markAsModuleRoot(componentView, moduleNamePath); | ||
| 63 | + if (componentView && moduleNamePath) { | ||
| 64 | + markAsModuleRoot(componentView, moduleNamePath); | ||
| 65 | + } | ||
| 64 | 66 | return componentView; | |
| 65 | 67 | } | |
| 66 | 68 | ||
@@ -164,6 +166,10 @@ function loadInternal(fileName: string, context?: any, moduleNamePath?: string): | |||
| 164 | 166 | (<any>componentModule.component).exports = context; | |
| 165 | 167 | } | |
| 166 | 168 | ||
| 169 | + if (!componentModule) { | ||
| 170 | + throw new Error("Failed to load component from module: " + filePathRelativeToApp + " or file: " + fileName); | ||
| 171 | + } | ||
| 172 | + | ||
| 167 | 173 | return componentModule; | |
| 168 | 174 | } | |
| 169 | 175 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments