Error testing a method that throws an Error in Quick with Nimble

3.5k views Asked by At

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 '() -> ()'
1

There are 1 answers

0
R2r On BEST ANSWER

try using expect with curly brackets { }

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

should be working