sahava/gtm-datalayer-test

Come up with a better alternative to the "not" : { "items" : { "not" pattern

sahava opened this issue · 0 comments

Currently the only way (I have found) to test if an array (window.dataLayer) simply contains an object is to use the

"type" : "array
"not" : {
    "items" : {
        "not" : {
            "type" : "object",
            "properties" : ...

pattern as used in /lib/testUtils.js. However, this is not only really ugly, but it also lacks proper validation error messages. If the test fails, the only thing the reporter knows is that the spec validated against a "not" condition. The reporter doesn't know what part of the spec failed. That's why there's the "FAILED ON: " workaround, where I expose the object on which the test failed in the error message.

As far as I know, there's not much to do about this yet. There's the "contains" keyword coming up (hopefully) in a future JSON Schema draft, but even then I'm not certain if it's descriptive enough.

So we need to figure out how to properly do an "array contains..." so that the validation error is still expressive enough to be informative.