Vue $el is undefined when testing with Mocha/Chai under meteor -
i'm starting our unit test environment our project, may have picked combo doesn't work in couple scenarios.
our project runs under meteor, code ui written in vue , coffeescript. test environment we're trying work mocha & chai. when run test suite, command looks this:
meteor test --once --driver-package=dispatch:mocha
from examples around internet, following code should work:
const vueobject = vue.extend(myvuecomponent); const vueinstance = new vueobject().$mount(); chai.assert.ok(vueinstance.$el.textcontent);
from point, ask $el sorts of questions test, $el undefined. tried waiting using vue.nexttick()
, it's still undefined. in examples i've found, talk using webpack, heard meteor doesn't using webpack.
does have suggestions? did pick hard combination work with?
tl;dr: make sure running tests in browser. if doesn't work try manually adding element when creating vue app.
i facing same issue jest.
initially, thought had create element manually when testing app, did:
test("do things", () => { const vm = new vue({ el: document.createelement("div"), render(h) { return h(hello); } }); expect(vm.$el.textcontent).tobe("heyo"); });
but document
undefined
. lead me discover should have been running tests using domjs
instead of node
"testenvironment": "jsdom"
with change in place, got rid of el
, still works charm.
Comments
Post a Comment