Error testing a method that throws an Error in Quick with Nimble
Asked Answered
R

1

11

I'm having a problem getting a Nimble matcher correct in testing a method that throws an exception. According to the docs it should be simple. I just need an expectation like this

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

However with Swift 3 and Xcode 8.2 I'm getting a compiler editor. Here's the context.

describe("Using RealmDatasource") {

   let datastore = RealmDatasource() as Datasource

       it("can retrieve an object") {

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

       }

}

I get the following error on the 'it' declaration line

Invalid conversion from throwing function of type '() -> () throws to non-throwing function of type '() -> ()'
Reneta answered 13/12, 2016 at 15:47 Comment(0)
B
18

try using expect with curly brackets { }

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

should be working

Backwoodsman answered 20/6, 2017 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.