import React from 'react'; import TestUtils from 'react-addons-test-utils'; import Formsy from './..'; import { customizeInput } from './utils/TestInput'; describe('Rules: isEmail', 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 pass with a default value', pass()); it('should fail with "foo"', fail('foo')); it('should pass with "foo@foo.com"', pass('foo@foo.com')); it('should pass with an undefined', pass(undefined)); it('should pass with a null', pass(null)); it('should pass with an empty string', pass('')); it('should fail with a number', fail(42)); });