2018-04-16 23:43:45 +08:00
|
|
|
module.exports = class FakeDocument {
|
|
|
|
constructor() {
|
|
|
|
this.head = this.createElement("head");
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement(type) {
|
|
|
|
return new FakeElement(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
getElementsByTagName(name) {
|
|
|
|
if (name === "head") return [this.head];
|
|
|
|
throw new Error(
|
|
|
|
`FakeDocument.getElementsByTagName(${name}): not implemented`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FakeElement {
|
2018-06-04 23:49:55 +08:00
|
|
|
constructor(type) {
|
2018-04-16 23:43:45 +08:00
|
|
|
this._type = type;
|
|
|
|
this._children = [];
|
|
|
|
this._attributes = Object.create(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendChild(node) {
|
|
|
|
this._children.push(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
setAttribute(name, value) {
|
|
|
|
this._attributes[name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAttribute(name) {
|
|
|
|
return this._attributes[name];
|
|
|
|
}
|
|
|
|
}
|