all files / tests/ utils.js

100% Statements 10/10
75% Branches 3/4
100% Functions 2/2
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18      36×   36×   36× 36× 36× 36× 36×   36×    
import { render, createElement, unmountComponentAtNode } from 'rax';
 
let id = 0;
export function renderSFCModule(Mod) {
  Eif (Mod && Mod.__esModule === true) {
    // 兼容 commonjs
    Mod = Mod.default;
  }
  const container = document.createElement('div');
  container.setAttribute('id', 'test-container-' + id++);
  document.body.appendChild(container);
  render(createElement(Mod, {}, []), container);
  container.unmount = () => {
    unmountComponentAtNode(container);
  };
  return container;
}