question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vm.$el.querySelector is not a function

See original GitHub issue

logs

INFO LOG: 'Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools'
ERROR LOG: '[Vue warn]: Error in render function: "TypeError: Cannot read property 'getters' of undefined"

(found in <Root>)'
ERROR LOG: TypeError{}
ERROR LOG: '[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'dispatch' of undefined"

(found in <Root>)'
ERROR LOG: TypeError{}

  testBox.vue
    ✗ should render correct contents
	TypeError: vm.$el.querySelector is not a function
	    at Context.<anonymous> (webpack:///test/unit/specs/testBox.spec.js:8:31 <- index.js:174106:30)


Chrome 60.0.3112 (Mac OS X 10.12.5): Executed 1 of 1 (1 FAILED) ERROR (0.629 secs / 0.012 secs)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! futures-adviser@1.0.0 unit: `cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-test@1.0.0 unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/.npm/_logs/2017-08-11T06_31_21_799Z-debug.log

and the desc file

import Vue from 'vue'
import chartBox from '@/components/testBox'

describe('testBox.vue', () => {
  it('should render correct contents', () => {
    const Constructor = Vue.extend(testBox);
    const vm = new Constructor().$mount();
    const topListItem = vm.$el.querySelector('.col-lg-25')
    expect(topListItem.length)
      .to.equal(7);
  })
})

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
LinusBorgcommented, Aug 18, 2017

You have to actually mount to an element.

https://jsfiddle.net/a0c1wm6t/1/

18reactions
fjy5314commented, Sep 19, 2017

求问你一下 你是怎么解决这个问题的

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: this.$el.querySelector is not a function nuxt filepond
Go to vue-filepond GitHub repo, download the file stored in lib/index.js . Put it somewhere in your codebase and edit the mounted function,...
Read more >
TypeError: querySelectorAll is not a function in JS | bobbyhadz
To solve the "querySelectorAll is not a function" error, make sure to only call the querySelectorAll method on a valid DOM element or...
Read more >
this.$el.querySelector is not a function while running tests vue.js
I have an expression showed below in mounted hook. But while running tests it throws an error this.$el.querySelector is not a function ....
Read more >
Getting an element within a component with Vue querySelector
Learn how to get an element within a component using its tag name, class name, or ID with the querySelector function in Vue....
Read more >
Selecting an element in a component via a queryselector
Thanks for the reply ! I get this error message this.$el.querySelector is not a function. the code ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found