75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
var React = require('react/addons');
|
|
var TestUtils = React.addons.TestUtils;
|
|
var Formsy = require('./../src/main.js');
|
|
|
|
describe('Rules: isEmptyString', function() {
|
|
var TestInput, isValid, form, input;
|
|
|
|
beforeEach(function() {
|
|
isValid = jasmine.createSpy('valid');
|
|
|
|
TestInput = React.createClass({
|
|
mixins: [Formsy.Mixin],
|
|
updateValue: function (event) {
|
|
this.setValue(event.target.value);
|
|
},
|
|
render: function () {
|
|
if (this.isValid()) {
|
|
isValid();
|
|
}
|
|
return <input value={this.getValue()} onChange={this.updateValue}/>
|
|
}
|
|
});
|
|
|
|
form = TestUtils.renderIntoDocument(
|
|
<Formsy.Form>
|
|
<TestInput name="foo" validations="isEmptyString"/>
|
|
</Formsy.Form>
|
|
);
|
|
|
|
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
TestInput = isValid = isInvalid = form = null;
|
|
});
|
|
|
|
it('should fail with non-empty string', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: 'asd'}});
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should pass with an empty string', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: ''}});
|
|
expect(isValid).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fail with a undefined', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: undefined}});
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fail with a null', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: null}});
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fail with a number', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: 123}});
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fail with a zero', function () {
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
TestUtils.Simulate.change(input, {target: {value: 0}});
|
|
expect(isValid).not.toHaveBeenCalled();
|
|
});
|
|
|
|
});
|