|
/*globals describe, beforeEach, afterEach, it, expect, Character */ |
|
describe("EverCraft", function () { |
|
"use strict"; |
|
describe("Characters", function () { |
|
it("should be defined", function () { |
|
expect(Character).toBeDefined(); |
|
}); |
|
describe("Attributes", function () { |
|
var character; |
|
|
|
beforeEach(function () { |
|
character = new Character({"name": "Balrock", "alignment": "Good"}); |
|
}); |
|
afterEach(function () { |
|
}); |
|
|
|
describe("#Name", function () { |
|
it("should be defined", function () { |
|
expect(character.getName).toBeDefined(); |
|
}); |
|
it("should allow for me to set the character's name to 'Balrock'", function () { |
|
expect(character.getName()).not.toBeNull(); |
|
}); |
|
it("should not allow for me to create a character without a name", function () { |
|
character = new Character(); |
|
expect(character).toBeNull(); |
|
}); |
|
it("should allow for me to retrieve the character's name", function () { |
|
expect(character.getName()).toEqual("Balrock"); |
|
}); |
|
}); |
|
describe("#Alignment", function () { |
|
it("should be defined", function () { |
|
expect(character.getAlignment).toBeDefined(); |
|
}); |
|
it("should allow for me to set the character's alignment to 'Good'", function () { |
|
expect(character.getAlignment()).toEqual("Good"); |
|
}); |
|
it("should allow for me to set the character's alignment to 'Evil'", function () { |
|
character = new Character({"name": "Balrock", "alignment": "Evil"}); |
|
expect(character.getAlignment()).toEqual("Evil"); |
|
}); |
|
it("should allow for me to set the character's alignment to 'Neutral'", function () { |
|
character = new Character({"name": "Balrock", "alignment": "Neutral"}); |
|
expect(character.getAlignment()).toEqual("Neutral"); |
|
}); |
|
it("should not allow for me to create a character with an alignment set to 'Nonsense'", function () { |
|
character = new Character({"name": "Balrock", "alignment": "Nonsense"}); |
|
expect(character).toBeNull(); |
|
}); |
|
}); |
|
}); |
|
}); |
|
}); |
The assertions you are making regarding validation are slightly off, I've made the tests pass by changing the assertions somewhat:
Note that validation doesn't actually prevent you from creating an instance of a model in Backbone given that instantiation happens client-side. The intended workflow of validate, as per the docs is to run on model.save() and model.set(), so you would create a model client-side with some attributes then attempt to save the data to the server. Once that happens you can code whatever validation logic to prevent an invalid model from being persisted.