File tree 2 files changed +32
-3
lines changed
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';
2
2
import Vue from 'vue' ;
3
3
import Mentions from '..' ;
4
4
import focusTest from '../../../tests/shared/focusTest' ;
5
+ import KeyCode from '../../_util/KeyCode' ;
5
6
6
- const { getMentions } = Mentions ;
7
+ const { getMentions, Option } = Mentions ;
7
8
8
9
function $$ ( className ) {
9
10
return document . body . querySelectorAll ( className ) ;
@@ -86,5 +87,28 @@ describe('Mentions', () => {
86
87
} ) ;
87
88
} ) ;
88
89
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
+
89
113
focusTest ( Mentions ) ;
90
114
} ) ;
Original file line number Diff line number Diff line change @@ -97,9 +97,14 @@ const Mentions = {
97
97
this . stopMeasure ( ) ;
98
98
} else if ( which === KeyCode . ENTER ) {
99
99
// Measure hit
100
- const option = this . getOptions ( ) [ activeIndex ] ;
101
- this . selectOption ( option ) ;
102
100
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 ) ;
103
108
}
104
109
} ,
105
110
/**
You can’t perform that action at this time.
0 commit comments