@@ -33,6 +33,38 @@ export default class Wrapper implements BaseWrapper {
3333 throwError ( 'at() must be called on a WrapperArray' )
3434 }
3535
36+ /**
37+ * Returns an Object containing all the attribute/value pairs on the element.
38+ */
39+ attributes ( ) : { [ name : string ] : string } {
40+ const attributes = [ ...this . element . attributes ] // NameNodeMap is not iterable
41+ const attributeMap = { }
42+ attributes . forEach ( ( att ) => {
43+ attributeMap [ att . localName ] = att . value
44+ } )
45+ return attributeMap
46+ }
47+
48+ /**
49+ * Returns an Array containing all the classes on the element
50+ */
51+ classes ( ) : Array < string > {
52+ let classes = [ ...this . element . classList ]
53+ // Handle converting cssmodules identifiers back to the original class name
54+ if ( this . vm && this . vm . $style ) {
55+ const cssModuleIdentifiers = { }
56+ let moduleIdent
57+ Object . keys ( this . vm . $style ) . forEach ( ( key ) => {
58+ moduleIdent = this . vm . $style [ key ]
59+ // CSS Modules may be multi-class if they extend others. Extended classes should be already present in $style.
60+ moduleIdent = moduleIdent . split ( ' ' ) [ 0 ]
61+ cssModuleIdentifiers [ moduleIdent ] = key
62+ } )
63+ classes = classes . map ( className => cssModuleIdentifiers [ className ] || className )
64+ }
65+ return classes
66+ }
67+
3668 /**
3769 * Checks if wrapper contains provided selector.
3870 */
@@ -309,6 +341,23 @@ export default class Wrapper implements BaseWrapper {
309341 return this . vnode . tag
310342 }
311343
344+ /**
345+ * Returns an Object containing the prop name/value pairs on the element
346+ */
347+ props ( ) : { [ name : string ] : any } {
348+ if ( ! this . isVueComponent ) {
349+ throwError ( 'wrapper.props() must be called on a Vue instance' )
350+ }
351+ // $props object does not exist in Vue 2.1.x, so use $options.propsData instead
352+ let _props
353+ if ( this . vm && this . vm . $options && this . vm . $options . propsData ) {
354+ _props = this . vm . $options . propsData
355+ } else {
356+ _props = this . vm . $props
357+ }
358+ return _props || { } // Return an empty object if no props exist
359+ }
360+
312361 /**
313362 * Sets vm data
314363 */
0 commit comments