MithrilJS / mithril-query

Query mithril virtual dom for testing purposes
MIT License
106 stars 33 forks source link

Support ES6 class components #78

Closed hmadison closed 6 years ago

hmadison commented 7 years ago

When using an ES6 class style component, I get an error like:

Sample > should have a div:
Class constructor Sample cannot be invoked without 'new'

Reproduction example:

global.window = require("mithril/test-utils/browserMock.js")()
global.document = window.document

var m = require("mithril") // version 1.1.1
var mq = require('mithril-query') // version 2.2.0
var o = require("mithril/ospec/ospec")

class Sample {
    constructor(vnode) {
    this._text = vnode.attrs.text
    }

    view() {
    return m("div", this._text)
    }
}

o.spec("Sample", function() {
    o("should have a div", function() {
    var output = mq(Sample, {text: "Text"})
    output.should.have(1, "div")
    })
})
StephanHoyer commented 7 years ago

that's a know issue. I try to fix this in the next few days or so.

StephanHoyer commented 7 years ago

Unfortunately this is not an trivial fix :(

Since I don't use class components, I don't have the time to fix this. Could need some assistance here