Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setup() {
const { createElement, render } = this.raxInstance;
const driver = this.driver = createDriver({
postMessage: this.sendMessageToRenderer,
addEventListener: this.addClientEvent,
});
driver.setDeviceWidth(global[MINIAPP_ENV].windowWidth);
const component = this.component = this.instantiatePage();
// 页面加载时触发
this.emitEvent('load', this.pageQuery);
render(createElement(component, {}), null, {
driver,
});
// 初始化 ready 事件, after render
this.emitEvent('ready', {});
global[CURRENT_CLIENT_ID] = this.clientId;
}
it('should render style once', (done) => {
function renderFactory(Rax) {
return function(data) {
return createElement('view', {
className: 'foo',
});
};
}
const cssText = '.foo { color: red; }';
const Comp = createComponent(renderFactory, Rax, {}, 'path/to/component', cssText);
global.setImmediate = null;
const driver = createWorkerDriver({
postMessage(message) {
expect(message).toMatchSnapshot();
done();
},
addEventListener() {},
});
class Page extends Rax.Component {
static contextTypes = { $page: null };
getChildContext() {
const $page = {
vnode: { _document: driver.document }
};
return { $page };
}