1

In my unit test, I get an Object and I can list the keys.
However, I can't get the value for a specific key:

wrapper = mount(Toolbar, { router, i18n });
const currentFlag= wrapper.find("#current-flag")
const currentFlagObject = currentFlag.attributes("src")
console.log(Object.keys(currentFlagObject))
console.log(currentFlagObject['src'])

console:

console.log tests/unit/Toolbar.spec.js:27
  [ 'id', 'src', 'width' ]
console.log tests/unit/Toolbar.spec.js:28
  [object Object]

Why can't i get the key value?

Maor Refaeli
  • 2,417
  • 2
  • 19
  • 33

2 Answers2

1
console.log(JSON.stringify(obj))

This will print the stringify version of object. So instead of [object Object] as an output you will get the content of object.

in your case it will be

console.log(JSON.stringify(currentFlagObject['src']))
Nitishkumar Singh
  • 1,781
  • 1
  • 15
  • 33
  • yes thanks ... and I discover that the src is anobject too.... a flag file.... not the path... –  Aug 28 '18 at 11:49
0

Try DOM getAttribute() Method

 currentFlag.getAttribute("src");
Chris Callwait
  • 142
  • 1
  • 4