gpt4 book ai didi

装饰器中的 Angular2 测试数据

转载 作者:太空狗 更新时间:2023-10-29 17:48:57 26 4
gpt4 key购买 nike

我有一个组件,我想在单元测试中检查选择器

@Component({
selector: 'my-component',
)}

我想这样测试

describe('My Component', function(){ 
it('should have a selector', function() {
expect( ___ ).toBe('my-component');
});
)}

最佳答案

您需要使用 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');
});
});

查看此插件:https://plnkr.co/edit/HQc1qt?p=preview .

关于装饰器中的 Angular2 测试数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36053166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com