Skip to content

Commit af6ee3a

Browse files
Update unit test (an integration test almost)
1 parent 44ac480 commit af6ee3a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

test/index.test.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import React from 'react'
22
import test from 'ava'
3-
import { renderToString } from '../src'
3+
import { renderToString, AMP } from '../src'
44
import styled from 'styled-components'
55

6-
test('RAMPT render', async t => {
6+
test('it renders simple node element', async t => {
77
const body = React.createElement('body', {})
88
const output = renderToString(body)
99
t.regex(output, /<body><\/body>/, 'Renders HTML template with body element.')
1010
})
1111

12+
const renderAllAMPComponents = () => {
13+
const Title = React.createElement(AMP.Title, {}, 'title')
14+
const Link = React.createElement(AMP.Link, { src: 'https://link' }, 'link')
15+
const body = React.createElement('body', {}, [Title, Link])
16+
return renderToString(body)
17+
}
18+
19+
test('it renders all AMP node element', t => {
20+
const render1 = renderAllAMPComponents()
21+
const render2 = renderAllAMPComponents()
22+
t.true(render1 === render2, 'Each render should not mix the state between each other.')
23+
t.snapshot(render1)
24+
})
25+
26+
1227
test('RAMPT render with styles', async t => {
1328
const styledBody = styled.body`background: red;`
1429
const body = React.createElement(styledBody, {})

test/snapshots/index.test.js.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Snapshot report for `test/index.test.js`
2+
3+
The actual snapshot is saved in `index.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## it renders all AMP node element
8+
9+
> Snapshot 1
10+
11+
`<!DOCTYPE html>␊
12+
<html ⚡>␊
13+
<head>␊
14+
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" />␊
15+
<script async="" src="https://cdn.ampproject.org/v0.js"></script>␊
16+
<title>title</title>␊
17+
<link src="https://link" />␊
18+
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>␊
19+
<style amp-custom=""></style>␊
20+
</head>␊
21+
<body></body>␊
22+
</html>`

test/snapshots/index.test.js.snap

474 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)