Skip to content

Commit 9d0e9a1

Browse files
committed
update test scripts
1 parent 6d229bf commit 9d0e9a1

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

test/e2e/specs/model.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3+
import { createInputNode } from '../util';
34

45
class Demo1 extends React.Component {
56
constructor(props) {
@@ -62,30 +63,30 @@ function Demo4({ fn, extraProps }) {
6263
}
6364

6465
describe('directive: model', () => {
65-
test('in class', () => {
66+
test('use in class: x-model', () => {
6667
const wrapper = mount(<Demo1/>);
67-
wrapper.find('input').simulate('change', { target: { value: 'new value' } });
68+
wrapper.find('input').simulate('change', createInputNode('new value'));
6869
expect(wrapper.find('.text').text()).toBe('new value');
6970
expect(wrapper.find('.extra').text()).toBe('B');
7071
});
7172

72-
test('use hook', () => {
73+
test('use in hook: x-model-hook', () => {
7374
const wrapper = mount(<Demo2/>);
74-
wrapper.find('input').simulate('change', { target: { value: 'new value' } });
75+
wrapper.find('input').simulate('change', createInputNode('new value'));
7576
expect(wrapper.find('.text').text()).toBe('new value');
7677
expect(wrapper.find('.extra').text()).toBe('foo');
7778
});
7879

7980
test('custom onChange event', () => {
8081
const wrapper = mount(<Demo3/>);
81-
wrapper.find('input').simulate('change', { target: { value: 'custom value' } });
82+
wrapper.find('input').simulate('change', createInputNode('custom value'));
8283
expect(wrapper.find('.text').text()).toBe('custom value');
8384
});
8485

8586
test('merge onChange', () => {
8687
const fn = jest.fn();
8788
const wrapper = mount(<Demo4 fn={fn}/>);
88-
wrapper.find('input').simulate('change', { target: { value: 'custom value' } });
89+
wrapper.find('input').simulate('change', createInputNode('custom value'));
8990
expect(wrapper.find('.text').text()).toBe('custom value');
9091
expect(fn.mock.calls.length).toBe(1);
9192
expect(fn.mock.calls[0][0].target.value).toBe('custom value');
@@ -98,7 +99,7 @@ describe('directive: model', () => {
9899
onChange: fn2
99100
};
100101
const wrapper = mount(<Demo4 fn={fn} extraProps={extraProps}/>);
101-
wrapper.find('input').simulate('change', { target: { value: 'custom value' } });
102+
wrapper.find('input').simulate('change', createInputNode('custom value'));
102103
expect(wrapper.find('.text').text()).toBe('custom value');
103104
expect(fn.mock.calls.length).toBe(0);
104105
expect(fn2.mock.calls.length).toBe(1);

test/e2e/specs/todo.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3+
import { createInputNode } from '../util';
34

45
class Todo extends React.Component {
56
constructor(props) {
@@ -55,23 +56,23 @@ describe('Todo Component', () => {
5556
const wrapper = mount(<Todo/>);
5657

5758
test('add todo', () => {
58-
wrapper.find('.input').simulate('change', { target: { value: 'First Todo' } });
59+
wrapper.find('.input').simulate('change', createInputNode('First Todo'));
5960
wrapper.find('.add').simulate('click');
6061
expect(wrapper.find('.todo-item .todo-text').at(0).text()).toBe('First Todo');
6162
expect(wrapper.find('.clear').prop('style').display).toBe(undefined);
6263
});
6364

6465
test('search todo', () => {
65-
wrapper.find('.input').simulate('change', { target: { value: 'Second Todo' } });
66+
wrapper.find('.input').simulate('change', createInputNode('Second Todo'));
6667
wrapper.find('.add').simulate('click');
6768

68-
wrapper.find('.input').simulate('change', { target: { value: 'First' } });
69+
wrapper.find('.input').simulate('change', createInputNode('First'));
6970
expect(wrapper.find('.todo-item .todo-text').length).toBe(1);
7071
expect(wrapper.find('.todo-item .todo-text').at(0).text()).toBe('First Todo');
7172
});
7273

7374
test('clear todo', () => {
74-
wrapper.find('.input').simulate('change', { target: { value: '' } });
75+
wrapper.find('.input').simulate('change', createInputNode(''));
7576
expect(wrapper.find('.todo-item .todo-text').length).toBe(2);
7677

7778
wrapper.find('.todo-item .remove').at(0).simulate('click');

test/e2e/util.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ export function sleep(ms) {
88
setTimeout(resolve, ms);
99
});
1010
}
11+
12+
/**
13+
* 创建类Input Node节点对象
14+
* @param value
15+
*/
16+
export function createInputNode(value) {
17+
const node = {};
18+
node.target = {
19+
nodeName: 'INPUT',
20+
nodeType: 1,
21+
value
22+
};
23+
return node;
24+
}

0 commit comments

Comments
 (0)