forked from jxnblk/repng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
54 lines (47 loc) · 1001 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const test = require('ava')
const React = require('react')
const isStream = require('is-stream')
const repng = require('./index')
// fixture
const Grid = ({
width = 256,
height = 256,
size = 2
}) => {
const rects = Array.from({ length: 32 / size })
.map((n, y) => (
Array.from({ length: 32 / size })
.map((n, x) => (
React.createElement('rect', {
width: size,
height: size,
fill: (x % 2 === (y % 2 ? 1 : 0)) ? 'black' : 'transparent',
x: size * x,
y: size * y,
})
))
))
return (
React.createElement('svg', {
viewBox: '0 0 32 32',
width,
height,
}, rects)
)
}
test('is a function', t => {
t.is(typeof repng, 'function')
})
test('returns a stream', async t => {
const width = 128
const height = width
const result = await repng(Grid, {
width,
height,
props: {
width,
height,
}
})
t.true(isStream(result))
})