forked from christianalfoni/formsy-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Semigradsky
committed
Jun 3, 2015
1 parent
d7e7dfc
commit 0395f61
Showing
13 changed files
with
298 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,28 @@ var Formsy = require('./../src/main.js'); | |
describe('Rules: isEmail', function() { | ||
var TestInput, isValid, form, input; | ||
|
||
beforeEach(function() { | ||
isValid = jasmine.createSpy('valid'); | ||
function pass(value) { | ||
return pass.length ? function () { | ||
TestUtils.Simulate.change(input, {target: {value: value}}); | ||
expect(isValid).toBe(true); | ||
} : function () { expect(isValid).toBe(true); }; | ||
} | ||
|
||
function fail(value) { | ||
return fail.length ? function () { | ||
TestUtils.Simulate.change(input, {target: {value: value}}); | ||
expect(isValid).toBe(false); | ||
} : function () { expect(isValid).toBe(false); }; | ||
} | ||
|
||
beforeEach(function() { | ||
TestInput = React.createClass({ | ||
mixins: [Formsy.Mixin], | ||
updateValue: function (event) { | ||
this.setValue(event.target.value); | ||
}, | ||
render: function () { | ||
if (this.isValid()) { | ||
isValid(); | ||
} | ||
isValid = this.isValid(); | ||
return <input value={this.getValue()} onChange={this.updateValue}/> | ||
} | ||
}); | ||
|
@@ -35,40 +45,18 @@ describe('Rules: isEmail', function() { | |
TestInput = isValid = isInvalid = form = null; | ||
}); | ||
|
||
it('should fail with "foo"', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: 'foo'}}); | ||
expect(isValid).not.toHaveBeenCalled(); | ||
}); | ||
it('should pass with a default value', pass()); | ||
|
||
it('should pass with "[email protected]"', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: '[email protected]'}}); | ||
expect(isValid).toHaveBeenCalled(); | ||
}); | ||
it('should fail with "foo"', fail('foo')); | ||
|
||
it('should fail with an undefined', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: undefined}}); | ||
expect(isValid).not.toHaveBeenCalled(); | ||
}); | ||
it('should pass with "[email protected]"', pass('[email protected]')); | ||
|
||
it('should fail with a null', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: null}}); | ||
expect(isValid).not.toHaveBeenCalled(); | ||
}); | ||
it('should pass with an undefined', pass(undefined)); | ||
|
||
it('should fail with a number', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: 42}}); | ||
expect(isValid).not.toHaveBeenCalled(); | ||
}); | ||
it('should pass with a null', pass(null)); | ||
|
||
it('should fail with an empty string', function () { | ||
expect(isValid).not.toHaveBeenCalled(); | ||
TestUtils.Simulate.change(input, {target: {value: ''}}); | ||
expect(isValid).not.toHaveBeenCalled(); | ||
}); | ||
it('should pass with an empty string', pass('')); | ||
|
||
it('should fail with a number', fail(42)); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.