【问题标题】:Error testing a method that throws an Error in Quick with Nimble使用 Nimble 测试在 Quick 中引发错误的方法时出错
【发布时间】:2016-12-13 15:47:44
【问题描述】:

在测试引发异常的方法时,我无法正确获取 Nimble 匹配器。根据文档,它应该很简单。我只需要这样的期望

expect( try somethingThatThrows() ).toNot( throwError() ) 

但是,使用 Swift 3 和 Xcode 8.2,我得到了一个编译器编辑器。这是上下文。

describe("Using RealmDatasource") {

   let datastore = RealmDatasource() as Datasource

       it("can retrieve an object") {

           expect( try datastore.getCurrentObject() ).to( throwError() )

       }

}

我在“it”声明行收到以下错误

Invalid conversion from throwing function of type '() -> () throws to non-throwing function of type '() -> ()'

【问题讨论】:

    标签: swift quick-nimble


    【解决方案1】:

    尝试使用带大括号 { } 的 expect

    expect { try datastore.getCurrentObject() }.to( throwError() )

    应该可以工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 2020-07-31
      • 2015-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多