import React from 'react';
import TestUtils from 'react-addons-test-utils';
import Formsy from './..';
import { customizeInput } from './utils/TestInput';
describe('Rules: isEmptyString', function () {
let Input, isValid, form, input;
function pass(value) {
return pass.length ? () => {
TestUtils.Simulate.change(input, {target: {value}});
expect(isValid).toBe(true);
} : () => expect(isValid).toBe(true);
}
function fail(value) {
return fail.length ? () => {
TestUtils.Simulate.change(input, {target: {value}});
expect(isValid).toBe(false);
} : () => expect(isValid).toBe(false);
}
beforeEach(() => {
Input = customizeInput({
render() {
isValid = this.isValid();
return ;
}
});
form = TestUtils.renderIntoDocument(
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
afterEach(() => {
Input = isValid = form = null;
});
it('should fail with a default value', fail());
it('should fail with non-empty string', fail('asd'));
it('should pass with an empty string', pass(''));
it('should fail with a undefined', fail(undefined));
it('should fail with a null', fail(null));
it('should fail with a number', fail(123));
it('should fail with a zero', fail(0));
});