我正在使用Angular CLI 1.0.0-beta.32.2并正在为Angular 2服务编写单元测试,该服务动态创建一个Component并将其插入另一个Component.
在我的单元测试中,我尝试创建一个模拟组件来测试我的服务,但输出会ng test抛出一个错误,说明我的模拟组件是在entryComponents属性中指定的.当我尝试将Component添加到entryComponentsTestModuleMetadata对象的属性中时,如下所示:TestBed.createTestingModule({...entryComponents: [ TestDialogComponent ]...})我看到以下错误说明该entryComponents属性不存在.
Chrome 56.0.2924 (Windows 10 0.0.0) DialogService should create a child component when opening FAILED
Error: No component factory found for TestDialogComponent. Did you add it to @NgModule.entryComponents?
查看TestModuleMetadata定义显示entryComponents属性不存在.那么如何在Angular 2和Jasmine的单元测试中动态创建一个Component呢?
我有一个非常小的项目,我正在尝试设置单元测试.直接使用时tsc项目编译正常,但是,当我尝试执行使用karma-typescript框架的测试时,我得到以下的Typescript编译错误:
错误:
错误[compiler.karma-typescript]:src/drawing/canvas.model.ts(1,23):错误TS2307:找不到模块'utils'.
错误[compiler.karma-typescript]:src/models/grid.model.ts(1,23):错误TS2307:找不到模块'utils'.
错误[compiler.karma-typescript]:src/utils/specs/obj.utils.spec.ts(1,23):错误TS2307:找不到模块'utils'.
项目结构: 我有一个项目设置,其结构如下:
|-dist/
|-node_modules/
|-src/
| |
| |-drawing/
| | |
| | |-canvas.model.ts
| | ________________________________
| | | import { Utils } from 'utils'; | Karma Fails (tsc is fine)
| | --------------------------------
| |
| |-models/
| | |
| | |-grid.model.ts
| | ________________________________
| | | import { Utils } from 'utils'; | Karma Fails (tsc is fine)
| | -------------------------------- …Run Code Online (Sandbox Code Playgroud) 在 SVG 中使用两个图像创建图像蒙版时,如何保留图像的不透明度?如下图所示,图像几乎是透明的 - 它应该是完全不透明的。为什么会发生这种情况?如何强制蒙版产品具有 100% 的不透明度?
这是我得到的结果:
这是我正在使用的蒙版图像:
这是我的代码(抱歉 PHP 变量):
<svg width="'.$width.'" height="'.$height.'" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<mask id="mask'.$id.'" maskUnits="userSpaceOnUse"
x="0" y="0" width="'.$width.'" height="'.$height.'">
<image id="maskImg'.$id.'" x="0" y="0" width="'.$width.'px" height="'.$height.'px"
xlink:href="images/'.$treatment_url.'" >
</image>
</mask>
<g id="imgGroup'.$id.'">
<rect x="0" y="0" width="'.$width.'" height="'.$height.'" fill="rgba(30,30,30,0.2)" />
<image id="listingImg'.$id.'"
x="0" y="0" width="'.$width.'px" height="'.$height.'px"
xlink:href="'. $img_url .'">
</image>
</g>
</defs>
<use xlink:href="#imgGroup'.$id.'" mask="url(#mask'.$id.')" opacity="1" />';
</svg>
Run Code Online (Sandbox Code Playgroud)
仅供参考:组<rect>中的<g>仅仅是当 MASKED 图像在 x 或 y 维度上小于 MASKING 图像时提供背景;它不会影响我遇到的掩蔽问题,因为我已经尝试了两种方法。
我很困惑,感谢任何帮助!
我对这里的语法有点困惑。
window.foo = window.bar || {};
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我只是想更好地理解 javaScript。谢谢
javascript ×2
typescript ×2
angular ×1
angular-cli ×1
image ×1
karma-runner ×1
masking ×1
svg ×1
syntax ×1
transparency ×1
unit-testing ×1