11import test from "ava" ;
22import { getComponent } from "../utils.js" ;
33
4+ class Event {
5+ constructor ( type ) {
6+ this . type = type ;
7+ }
8+ }
9+ global . Event = Event ;
10+
411test ( "modelEls" , ( t ) => {
512 const component = getComponent ( ) ;
613
@@ -17,7 +24,7 @@ test("abbreviated name", (t) => {
1724 t . is ( component . modelEls . length , 1 ) ;
1825} ) ;
1926
20- test ( "model.lazy has input and blur events " , ( t ) => {
27+ test ( "model.lazy has input and blur events" , ( t ) => {
2128 const html = `
2229 <div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
2330 <input u:model.lazy='name'></input>
@@ -30,3 +37,54 @@ test("model.lazy has input and blur events ", (t) => {
3037
3138 t . is ( element . events . length , 2 ) ;
3239} ) ;
40+
41+ test ( "model trigger with invalid key" , ( t ) => {
42+ t . plan ( 0 ) ;
43+
44+ const html = `
45+ <div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
46+ <input u:model.lazy='name' u:key='nameKey'></input>
47+ </div>` ;
48+ const component = getComponent ( html ) ;
49+ const element = component . modelEls [ 0 ] ;
50+
51+ element . el . dispatchEvent = ( ) => {
52+ t . pass ( ) ;
53+ } ;
54+
55+ component . trigger ( "invalidNameKey" ) ;
56+ } ) ;
57+
58+ test ( "model.lazy trigger" , ( t ) => {
59+ t . plan ( 1 ) ;
60+
61+ const html = `
62+ <div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
63+ <input u:model.lazy='name' u:key='nameKey'></input>
64+ </div>` ;
65+ const component = getComponent ( html ) ;
66+ const element = component . modelEls [ 0 ] ;
67+
68+ element . el . dispatchEvent = ( event ) => {
69+ t . true ( event . type === "blur" ) ;
70+ } ;
71+
72+ component . trigger ( "nameKey" ) ;
73+ } ) ;
74+
75+ test ( "model trigger" , ( t ) => {
76+ t . plan ( 1 ) ;
77+
78+ const html = `
79+ <div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
80+ <input u:model='name' u:key='nameKey'></input>
81+ </div>` ;
82+ const component = getComponent ( html ) ;
83+ const element = component . modelEls [ 0 ] ;
84+
85+ element . el . dispatchEvent = ( event ) => {
86+ t . true ( event . type === "input" ) ;
87+ } ;
88+
89+ component . trigger ( "nameKey" ) ;
90+ } ) ;
0 commit comments