File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import { mount } from '@vue/test-utils';
22import Vue from 'vue' ;
33import Mentions from '..' ;
44import focusTest from '../../../tests/shared/focusTest' ;
5+ import KeyCode from '../../_util/KeyCode' ;
56
6- const { getMentions } = Mentions ;
7+ const { getMentions, Option } = Mentions ;
78
89function $$ ( className ) {
910 return document . body . querySelectorAll ( className ) ;
@@ -86,5 +87,28 @@ describe('Mentions', () => {
8687 } ) ;
8788 } ) ;
8889
90+ it ( 'notExist' , async ( ) => {
91+ const wrapper = mount ( {
92+ render ( ) {
93+ return (
94+ < Mentions >
95+ < Option value = "bamboo" > Bamboo</ Option >
96+ < Option value = "light" > Light</ Option >
97+ < Option value = "cat" > Cat</ Option >
98+ </ Mentions >
99+ ) ;
100+ } ,
101+ } ) ;
102+
103+ triggerInput ( wrapper , '@notExist' ) ;
104+ jest . runAllTimers ( ) ;
105+
106+ wrapper . find ( 'textarea' ) . element . keyCode = KeyCode . ENTER ;
107+ wrapper . find ( 'textarea' ) . trigger ( 'keydown' ) ;
108+ jest . runAllTimers ( ) ;
109+
110+ expect ( wrapper . find ( 'textarea' ) . element . value ) . toBe ( '@notExist' ) ;
111+ } ) ;
112+
89113 focusTest ( Mentions ) ;
90114} ) ;
Original file line number Diff line number Diff line change @@ -97,9 +97,14 @@ const Mentions = {
9797 this . stopMeasure ( ) ;
9898 } else if ( which === KeyCode . ENTER ) {
9999 // Measure hit
100- const option = this . getOptions ( ) [ activeIndex ] ;
101- this . selectOption ( option ) ;
102100 event . preventDefault ( ) ;
101+ const options = this . getOptions ( ) ;
102+ if ( ! options . length ) {
103+ this . stopMeasure ( ) ;
104+ return ;
105+ }
106+ const option = options [ activeIndex ] ;
107+ this . selectOption ( option ) ;
103108 }
104109 } ,
105110 /**
You can’t perform that action at this time.
0 commit comments