From f08f85d484fb01fb42f852b225770e0c0a0c7590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=BE=9C?= Date: Thu, 26 Sep 2019 17:31:41 +0800 Subject: [PATCH 1/8] test: basic rendering --- .../src/__tests__/basic.js | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 packages/rax-server-renderer/src/__tests__/basic.js diff --git a/packages/rax-server-renderer/src/__tests__/basic.js b/packages/rax-server-renderer/src/__tests__/basic.js new file mode 100644 index 0000000000..56b36b6328 --- /dev/null +++ b/packages/rax-server-renderer/src/__tests__/basic.js @@ -0,0 +1,114 @@ +/* @jsx createElement */ + +import {createElement, useState, useEffect, createContext, useContext, useReducer} from 'rax'; +import {renderToString} from '../index'; + +describe('renderToString', () => { + describe('basic rendering', function() { + it('render a blank div', () => { + function MyComponent() { + return
; + } + + let str = renderToString(); + expect(str).toBe('
'); + }); + + it('a self-closing tag', () => { + function MyComponent() { + return
; + } + + let str = renderToString(); + expect(str).toBe('
'); + }); + + it('a self-closing tag as a child', () => { + function MyComponent() { + return ( +
+
+
+ ); + } + + let str = renderToString(); + expect(str).toBe('

'); + }); + + it('a string', () => { + function MyComponent() { + return 'Hello'; + } + + let str = renderToString(); + expect(str).toBe('Hello'); + }); + + it('a number', () => { + function MyComponent() { + return 42; + } + + let str = renderToString(); + expect(str).toBe('42'); + }); + + it('an array with one child', () => { + function MyComponent() { + return [
text1
]; + } + + let str = renderToString(); + expect(str).toBe('
text1
'); + }); + + it('an array with several children', () => { + let Header = props => { + return

header

; + }; + let Footer = props => { + return [

footer

,

about

]; + }; + + function MyComponent() { + return [ +
text1
, + text2, +
, +