【问题标题】:Angular 1/Jasmine - Test return type of functionAngular 1/Jasmine - 测试函数的返回类型
【发布时间】:2017-07-17 05:02:20
【问题描述】:

我想测试一个函数的返回类型,是布尔值还是数字...

通过这段代码我测试了函数是否存在,如何通过测试返回类型来推送测试?

it('should expose a showMonthlyRentDate function', () => {
  expect(ctrl.showMonthlyRentDate).toBeDefined()
   expect(typeof ctrl.showMonthlyRentDate).toBe('function')
 })

【问题讨论】:

    标签: javascript angularjs unit-testing jasmine karma-jasmine


    【解决方案1】:

    是的

    expect(ctrl.showMonthlyRentDate()).toEqual(jasmine.any(Number));
    

    最好使用jasmine.any,因为它可以在测试失败时提供更有意义的反馈。

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 1970-01-01
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多