🥝
Cypress Notlari
  • 🥑1. Cypress – Giriş
  • 📐2. Cypress Kurulum
  • 🥳3. Test Runner
  • 🔥4. Cypress ile İlk Test
  • ⚔️5. Cypress Destekleyen Tarayıcılar
  • 🦇6. Cypress Basit Komutlar
  • 👾7. Cypress Değişkenler (Variables)
  • 😎8. Cypress Aliases
  • 👻9. Cypress Locators
  • ☝️10. Cypress Assertions(iddia)
  • 📔11. Cypress Metin Doğrulaması
  • 🧞12. Cypress Eşzamansız Davranış(Asynchronous Behavior)
  • 🦊13. Cypress XHR ile çalışma
  • ✅14. Cypress Checkbox
  • 🍪15. Cypress Cookie İşlemleri
  • ☘️16. Cypress Get ve Post İşlemleri
  • 🦆17. Api Response Data Type Kontrolu
  • ☔18. Chai Json Schema
  • 🥳19. Chai ile Schema Oluşturma Örnekleri
  • 🇲🇬20. Cypress Fixtures
  • 🆓21. Cypress — Dashboard Hackliyoruz
  • 🎥22. Cypress Screenshotlar ve Videolar
  • 😋23. Cypress Debugging
  • 🛃24. Cypress Custom Commands
  • 📖25. Cypress Environment Variables
  • 🪝26. Cypress Hooks
  • 🎑27. Cypress Reports
  • ⛳28.Best Practices
  • Kaynakça
Powered by GitBook
On this page
  • 1. Örnek
  • 2.Örnek

19. Chai ile Schema Oluşturma Örnekleri

1. Örnek

// Data
const validData = {
    name: "Furkan", // required field => string
    age: 24 // optional => null or number
}

const invalidData = {
    name: 24, // required field => string
    age: "Furkan" // optional => null or number
}

// Schema
const dataSchema = {
    title: "Data Schema",
    type: "object",
    required: ["name"],
    properties: {
        name: {
            type: "string"
        },
        age: {
            type: ["number", "null"],
        }
    }
}

Cypress testlerini yazalım.

// Cypress test
it("test schema with valid data", () => {
    expect(validData).to.be.jsonSchema(dataSchema);
})
 
// Cypress test
it("test schema with invalid data", () => {
    expect(badData).to.not.be.jsonSchema(dataSchema);
})

2.Örnek

// Data
const goodApple = {
    skin: "thin",
    colors: ["red", "green", "yellow"],
    taste: 10,
};

const badApple = {
    colors: ["brown"],
    taste: 0,
    worms: 2,
};

// Schema
const fruitSchema = {
	title: "fresh fruit schema ",
	type: "object",
	required: ["skin", "colors", "taste"],
	properties: {
		colors: {
		   type: ["array", "null"], // null değerleri de kabul eder
		   minItems: 1,
		   uniqueItems: true,
		   items: {
			   type: "string",
		    },
		},
		skin: {
		    type: "string",
		},
		taste: {
		    type: "number",
		    minimum: 5,
		},
	},
};

Cypress testlerini yazalım.

// Cypress test
it("test schema with valid data", () => {
    expect(goodApple).to.be.jsonSchema(fruitSchema);
})
 
// Cypress test
it("test schema with invalid data", () => {
    expect(badApple).to.not.be.jsonSchema(fruitSchema);
})
Previous18. Chai Json SchemaNext20. Cypress Fixtures

Last updated 2 years ago

🥳