|
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 | +} |
0 commit comments