Skip to content

Commit 6ab090b

Browse files
committed
test: add unit tests for jest-snapshot-plugin
1 parent 8491923 commit 6ab090b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"karma-mocha": "^1.3.0",
5656
"karma-webpack": "^3.0.5",
5757
"mocha": "^5.2.0",
58+
"pretty-format": "^26.0.1",
5859
"webpack": "^4.41.2",
5960
"webpack-cli": "^3.3.10"
6061
},
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const prettyFormat = require('pretty-format')
2+
const snapshotPlugin = require('../../src/jest-snapshot-plugin')
3+
4+
const testSymbol =
5+
typeof Symbol === 'function' && Symbol.for
6+
? Symbol.for('j-component.json')
7+
: 0xd846fe
8+
9+
test('snapshot', () => {
10+
const str = prettyFormat(
11+
{
12+
$$typeof: testSymbol,
13+
tagName: 'view',
14+
attrs: [{name: 'class', value: 'weui'}],
15+
event: {
16+
tap: {
17+
handler: 'onTap',
18+
id: 0,
19+
isCapture: true,
20+
isCatch: false,
21+
isMutated: true,
22+
name: 'tap',
23+
},
24+
},
25+
children: [
26+
'hello ',
27+
{
28+
$$typeof: testSymbol,
29+
tagName: 'view',
30+
attrs: [],
31+
event: {},
32+
children: [],
33+
},
34+
],
35+
},
36+
{plugins: [snapshotPlugin]}
37+
)
38+
expect(str).toEqual(
39+
'<view\n class="weui"\n capture-mut-bind:tap="onTap"\n>\n hello \n <view />\n</view>'
40+
)
41+
})

0 commit comments

Comments
 (0)