Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render(, container);
expect(renderCount).toBe(1);
expect(container.querySelector('div').textContent).toBe('hi');
data.z = 'hello';
// no re-rendering on static rendering
expect(renderCount).toBe(1);
expect(container.querySelector('div').textContent).toBe('hi');
expect(renderCount).toBe(1);
expect(getDNode(data, 'z').observers.length).toBe(0);
useStaticRendering(false);
});
import { useStaticRendering } from 'inferno-mobx'
import { toJS } from 'mobx'
import Account from '../models/Account'
import State from '../../src/stores/State'
import context from '../../src/config/context'
useStaticRendering(true)
const stateClone = JSON.stringify(toJS(new State({})))
/**
* Middleware for creating the context
* @param ctx
* @param next
*/
export default async(ctx, next) => {
// Get our token from headers (server) or cookies (client)
ctx.token = ctx.headers['token'] || ctx.cookies.get('token')
// Check if logged in
ctx.account = await Account.getAccount(ctx.token)
// Create state for SSR
it('does not views alive when using static rendering', () => {
useStaticRendering(true);
let renderCount = 0;
const data = mobx.observable({
z: 'hi'
});
const TestComponent = observer(function testComponent() {
renderCount++;
return <div>{data.z}</div>;
});
render(, container);
expect(renderCount).toBe(1);
expect(container.querySelector('div').textContent).toBe('hi');
it('does not views alive when using static + string rendering', function() {
useStaticRendering(true);
let renderCount = 0;
const data = mobx.observable({
z: 'hi'
});
const TestComponent = observer(function testComponent() {
renderCount++;
return <div>{data.z}</div>;
});
const output = renderToStaticMarkup();
data.z = 'hello';
expect(output).toBe('<div>hi</div>');
const TestComponent = observer(function testComponent() {
renderCount++;
return <div>{data.z}</div>;
});
const output = renderToStaticMarkup();
data.z = 'hello';
expect(output).toBe('<div>hi</div>');
expect(renderCount).toBe(1);
expect(getDNode(data, 'z').observers.length).toBe(0);
useStaticRendering(false);
});
});