Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.

Commit cc0ee8c

Browse files
committed
add test
1 parent 322f60f commit cc0ee8c

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"express": "^4.14.0",
7676
"file-loader": "^0.9.0",
7777
"html-webpack-plugin": "^2.24.1",
78+
"jsdom": "^9.11.0",
7879
"mocha": "^3.2.0",
7980
"node-sass": "^4.1.1",
8081
"react": "^15.4.2",

test/jsdom.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import jsdom from 'jsdom';
2+
3+
if (typeof document === 'undefined') {
4+
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
5+
global.window = document.defaultView;
6+
global.navigator = global.window.navigator;
7+
}

test/setup.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import React from 'react';
66
import { expect } from 'chai';
77
import { shallow, render, mount } from 'enzyme';
8+
import './jsdom';
89
import {
910
TextApp1,
1011
TextApp2,
@@ -32,3 +33,41 @@ describe('Test to create a basic form', () => {
3233
});
3334

3435
});
36+
37+
38+
describe('Test Form change validation', () => {
39+
it('The form is validated correctly', () => {
40+
const app = mount(
41+
<TextApp2
42+
classNames={{
43+
static: 'form-control',
44+
success: 'valid-success',
45+
error: 'valid-error',
46+
}}
47+
values={{ email: '' }}
48+
/>,
49+
);
50+
const input = app.find('input');
51+
const label = app.find('label');
52+
53+
expect(label.text()).to.be.empty;
54+
// trigger
55+
input.simulate('change');
56+
expect(input.props().className).to.contains('valid-error');
57+
expect(label.text()).to.equal('Can not be empty!');
58+
expect(app.node.formValues.email).to.be.empty;
59+
// Change
60+
input.get(0).value = 'example#example.com';
61+
input.simulate('change');
62+
expect(label.text()).to.equal('Please enter a valid email address.');
63+
expect(app.node.isAllValid).to.equal(false);
64+
// Change
65+
input.get(0).value = 'example@example.com';
66+
input.simulate('change');
67+
expect(label.text()).to.be.empty;
68+
expect(input.props().className).to.contains('valid-success');
69+
expect(app.node.isAllValid).to.equal(true);
70+
});
71+
72+
// it('Initialize the parameter by function', () => {});
73+
});

0 commit comments

Comments
 (0)