首页 > 解决方案 > 如何为 json 模式编写测试?

问题描述

我已经使用 JSON 模式创建了我的 UI,我很困惑如何为它编写测试?我在网上查看了各种资源,但不知道如何开始。我想测试一下,如果单选按钮为真,那么下拉菜单会显示,并且下拉菜单中还有输入字段。这是我的代码,我想使用 javascript 或酶对其进行测试:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "definitions": {
  },
  "type": "object",
  "properties": {
    "enabled": {
      "title": "click me to enable this radiobutton",
      "type": "boolean",
      "default": false
    }
  },
  "dependencies": {
    "enabled": {
      "oneOf": [
        {
          "properties": {
            "enabled": {
              "enum": [
                false
              ]
            }
          }
        },
        {
          "properties": {
            "enabled": {
              "enum": [
                true
              ]
            },
            "style": {
              "title": "Color Type",

              "enum": [
                "rainbow",
                "primaryColors",
                "mixedColors"
              ],

              "enumNames": [
                "Rainbow",
                "Primary",
                "Mixed"
              ],
              "default": "primaryColors"
            }

          },
          "dependencies": {
            "style": {
              "oneOf": [
                {
                  "properties": {
                    "style": {
                      "enum": [
                        "rainbow"
                      ]
                    },
                    "violet": {
                      "title": "Violet",
                      "type": "string"
                    }
                  }
                },
                {
                  "properties": {
                    "style": {
                      "enum": [
                        "primaryColors"
                      ]
                    },
                    "red": {
                      "title": "this is red",
                      "type": "string"

                    }
                  }
                },
                {
                  "properties": {
                    "style": {
                      "enum": [
                        "mixedColors"
                      ]
                    },
                    "pink": {
                      "title": "I am pink",
                      "type": "string"
                    }
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

标签: jsonunit-testingtestingenzymejsonschema

解决方案


推荐阅读