How to perform an assert.NotElementsMatch() #1592
-
Hi, Just getting started with Testify. Couldn't find a method to perform the above.
How would I do this with Testify? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
We should probably have a NotElementsMatch assertion, if you want to open an issue or pull request for that we would be open to adding it. How would I do it right now? This is a hack, and it might not work in future Go versions: package kata_test
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIfy(t *testing.T) {
s1 := []string{"cat", "bat", "rat"}
s2 := []string{"bat", "cat", "rat"}
s3 := []string{"cow", "pig", "dog"}
assertNotElementsMatch(t, s1, s2)
assertNotElementsMatch(t, s1, s3)
}
func assertNotElementsMatch(t *testing.T, listA, listB any) bool {
t.Helper()
return assert.False(t, assert.ElementsMatch(new(testing.T), listA, listB), "Lists have the same elements:\n%v\n%v", listA, listB)
} |
Beta Was this translation helpful? Give feedback.
-
this assertion has been added in #1600 |
Beta Was this translation helpful? Give feedback.
this assertion has been added in #1600
I think we can close this question @jdycaico