Skip to content

Commit

Permalink
don't panic on Eventually(nil), fixing #555 (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
thediveo authored Jul 28, 2022
1 parent 8e37808 commit 9d1186f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/async_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g
}

switch actualType := reflect.TypeOf(actualInput); {
case actualType.Kind() != reflect.Func:
case actualInput == nil || actualType.Kind() != reflect.Func:
out.actualValue = actualInput
case actualType.NumIn() == 0 && actualType.NumOut() > 0:
out.actualIsFunc = true
Expand Down
18 changes: 18 additions & 0 deletions internal/async_assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,4 +742,22 @@ var _ = Describe("Asynchronous Assertions", func() {

})

Context("eventual nil-ism", func() { // issue #555

It("doesn't panic on nil actual", func() {
ig := NewInstrumentedGomega()
Expect(func() {
ig.G.Eventually(nil).Should(BeNil())
}).NotTo(Panic())
})

It("doesn't panic on function returning nil error", func() {
ig := NewInstrumentedGomega()
Expect(func() {
ig.G.Eventually(func() error { return nil }).Should(BeNil())
}).NotTo(Panic())
})

})

})

0 comments on commit 9d1186f

Please sign in to comment.