我有一个组件,我想在单元测试中检查选择器
@Component({
selector: 'my-component',
)}
Run Code Online (Sandbox Code Playgroud)
我想这样测试
describe('My Component', function(){
it('should have a selector', function() {
expect( ___ ).toBe('my-component');
});
)}
Run Code Online (Sandbox Code Playgroud)
您需要使用Reflect Metadata来访问这些提示.假设组件的类是MyComponent,您可以这样做来测试选择器:
describe('My Component', function(){
it('should have a selector', function() {
var annotations = Reflect.getMetadata('annotations', MyComponent);
// Supposing the first annotations is of type ComponentMetadata
expect(annotations[0].selector).toBe('my-component');
});
});
Run Code Online (Sandbox Code Playgroud)
请参阅此plunkr:https://plnkr.co/edit/HQc1qt ? p = preview .
| 归档时间: |
|
| 查看次数: |
542 次 |
| 最近记录: |