简体   繁体   English

如何在 Jest/Jasmine 单元测试中测试方法属性

[英]How test the method property in Jest/Jasmine unit testing

I need to test the property of the method in jest.我需要开玩笑地测试方法的属性。 My test is passing but test coverage is not increasing.我的测试通过了,但测试覆盖率没有增加。

How test the property of methods?如何测试方法的属性?

component.ts组件.ts

 onClickExpanding() {
        this.ownerName = this.getControl();
        this.quest.parent.children.forEach(c=> c.Grp = false);
        this.quest.Grp = true;
      }

TestCase测试用例

it('onClickExpandingtest all property', () => {
  copoment.quest.Grp= true;
  expect(component.onClickExpanding).toBeTruthy();
});

Right now you are just checking if the method exists - that is why test coverage is not increasing.现在您只是在检查该方法是否存在——这就是测试覆盖率没有增加的原因。 If you are setting private component properties you can use the following syntax: expect(copoment['ownerName ']).toBe(whatever).如果要设置私有组件属性,可以使用以下语法:expect(copoment['ownerName ']).toBe(whatever)。 If the property is public you can just access it via component.property..如果该属性是公开的,您可以通过 component.property.. 访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 笑话单元测试 - 如何在笑话中基于真/假对 if/else 条件和调用方法进行单元测试? - Jest Unit Testing - how to unit test if/else condition and call method based on true/false inside jest? 如何使用茉莉花测试对 mapbox 弹出窗口进行单元测试? - How to unit test a mapbox popup with jasmine testing? 如何使用Jasmine对链式方法进行单元测试 - How to unit test a chained method using Jasmine 如何在角组件与服务交互的地方使用茉莉花因果单元测试来测试.subscribe方法? - How to test .subscribe method using jasmine karma unit testing where angular components is interacting with service? 茉莉花单元测试被称为方法 - jasmine unit testing was method called 开玩笑的单元测试-测试setState() - Jest unit testing - test setState() 茉莉花单元测试 - 测试对象的未定义属性 - jasmine unit testing - testing for an undefined property of an object Angular-cli Jasmine单元测试中如何监视方法 - How to spy method in angular-cli Jasmine unit testing 茉莉花单元测试:如何在传递给被测方法的函数参数中监视Function.prototype.call()? - Jasmine Unit Testing: How can I spy on Function.prototype.call() in a function parameter that is passed to my method under test? 如何在 JEST 单元测试中为 FindAll() 方法使用 bcrypt - How to use bcrypt in JEST Unit Testing for a FindAll() Method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM