I love karate's fuzzy matching feature. I'm wondering if it's possible to use it outside of karate. Is there an internal or external dependency one can use to take full advantage of the same fuzzy matching capability? Thanks!
Yes, it is available via a pure Java API if you use the karate-core
dependency. Here is an example:
@Test
void testApiUsage() {
Match.that("[1, 2, 3]").contains(2);
Match.that("[1, 2, 3]").isEachEqualTo("#number");
Match.that("[1, 2, 3]").containsOnly("[3, 2, 1]");
Match.that("{ a: 1, b: 2 }").contains("{ b: 2 }");
Match.that("{ a: 1, b: 2, c: { d: 3, e: 4} }").containsDeep("{ b: 2, c: { e: 4 } }");
}
As of today, Karate depends on Graal-JS which unfortunately brings in a lot of bloat in terms of dependencies. It should not matter for most teams using this in test
scope. This will be resolved in the future when we switch to our own JS engine.