JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://wzrd.in/standalone/expect@latest"></script>
<body>
</body>
Babel + JSX
document.body.innerHTML = 'Running tests';
// Copy all static properties of class to an insantiation
const newWithStatic = (source, ...args) => {
let newObj = new source(...args);
Object.getOwnPropertyNames(source)
.filter(prop => typeof source[prop] === "function")
.forEach(prop => {
newObj[prop] = source[prop];
});
return newObj;
};
const test = () => {
class Test {
constructor (x) {
this.x = x;
}
static identity (i) {
return i;
}
getX (x) {
return this.x;
}
}
let obj = newWithStatic(Test, true)
expect(obj.identity(false)).toEqual(false);
expect(obj.getX()).toEqual(true);
};
test();
document.body.innerHTML = 'All tests passed';