Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Chapter 11: validation should check for "invalid" event #363

Merged
merged 1 commit into from
Mar 5, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions chapters/11-unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,18 @@ Next, it is common to include validation logic in your models to ensure that inp

A Todo app may wish to validate the text input supplied in case it contains rude words. Similarly if we're storing the ```done``` state of a Todo item using booleans, we need to validate that truthy/falsy values are passed and not just any arbitrary string.

In the following spec, we take advantage of the fact that validations which fail model.validate() trigger an "error" event. This allows us to test if validations are correctly failing when invalid input is supplied.
In the following spec, we take advantage of the fact that validations which fail model.validate() trigger an "invalid" event. This allows us to test if validations are correctly failing when invalid input is supplied.

We create an errorCallback spy using Jasmine's built in ```createSpy()``` method which allows us to spy on the error event as follows:
We create an errorCallback spy using Jasmine's built in ```createSpy()``` method which allows us to spy on the invalid event as follows:

```javascript
it('Can contain custom validation rules, and will trigger an error event on failed validation.', function() {
it('Can contain custom validation rules, and will trigger an invalid event on failed validation.', function() {

var errorCallback = jasmine.createSpy('-error event callback-');

var todo = new Todo();

todo.on('error', errorCallback);
todo.on('invalid', errorCallback);

// What would you need to set on the todo properties to
// cause validation to fail?
Expand Down