File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
test/unit/specs/mount/Wrapper Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,10 @@ export default class Wrapper implements BaseWrapper {
312
312
* Return text of wrapper element
313
313
*/
314
314
text ( ) : string {
315
+ if ( ! this . element ) {
316
+ throwError ( 'cannot call wrapper.text() on a wrapper without an element' )
317
+ }
318
+
315
319
return this . element . textContent
316
320
}
317
321
Original file line number Diff line number Diff line change @@ -9,4 +9,13 @@ describe('text', () => {
9
9
10
10
expect ( wrapper . text ( ) ) . to . equal ( text )
11
11
} )
12
+
13
+ it ( 'throws error if wrapper does not contain eleemnt' , ( ) => {
14
+ const compiled = compileToFunctions ( `<div />` )
15
+ const wrapper = mount ( compiled )
16
+ wrapper . element = null
17
+ const fn = ( ) => wrapper . text ( )
18
+ const message = '[vue-test-utils]: cannot call wrapper.text() on a wrapper without an element'
19
+ expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
20
+ } )
12
21
} )
You can’t perform that action at this time.
0 commit comments