Skip to content

Commit

Permalink
Add test to ensure that isomorphic rendering works both with and with…
Browse files Browse the repository at this point in the history
…out jsdom
  • Loading branch information
Robert-Frampton authored and Robert-Frampton committed Nov 14, 2017
1 parent be849c1 commit 95d7ae3
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/metal-isomorphic/test/isomorphic.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import Component from 'metal-component';
import MyComponent from './fixtures/MyComponent';
import MyJSXComponent from './fixtures/MyJSXComponent';
import jsdomGlobal from 'jsdom-global';
import { assert } from 'chai';

describe('Isomorphic Rendering', () => {
it('should render soy component to string', () => {
assert.ok(!global.document);

const htmlString = Component.renderToString(MyComponent, {
message: 'Hello, Soy!'
});
Expand All @@ -13,10 +16,64 @@ describe('Isomorphic Rendering', () => {
});

it('should render jsx component to string', () => {
assert.ok(!global.document);

const htmlString = Component.renderToString(MyJSXComponent, {
message: 'Hello, JSX!'
});

assert.equal(htmlString, '<div>Hello, JSX!</div>');
});

describe('JSDom', () => {
let cleanup;

before(() => {
cleanup = jsdomGlobal();
});

after(() => {
cleanup();
});

it('should render soy component to string', () => {
assert.ok(document);

const htmlString = Component.renderToString(MyComponent, {
message: 'Hello, Soy!'
});

assert.equal(htmlString, '<div>Hello, Soy!</div>');
});

it('should render soy component to DOM', () => {
assert.ok(document);

const comp = new MyComponent({
message: 'Hello, Soy!'
});

assert.equal(comp.element.innerHTML, '<div>Hello, Soy!</div>');
});

it('should render jsx component to string', () => {
assert.ok(document);

const htmlString = Component.renderToString(MyJSXComponent, {
message: 'Hello, JSX!'
});

assert.equal(htmlString, '<div>Hello, JSX!</div>');
});

it('should render JSX component to DOM', () => {
assert.ok(document);

const comp = new MyJSXComponent({
message: 'Hello, Soy!'
});

assert.equal(comp.element.innerHTML, '<div>Hello, Soy!</div>');
});
});
});

0 comments on commit 95d7ae3

Please sign in to comment.