11import React from 'react' ;
22import { mount } from 'enzyme' ;
3+ import { createInputNode } from '../util' ;
34
45class Demo1 extends React . Component {
56 constructor ( props ) {
@@ -62,30 +63,30 @@ function Demo4({ fn, extraProps }) {
6263}
6364
6465describe ( '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 ) ;
0 commit comments