Skip to content

Commit 247eea2

Browse files
committed
Extract test helpers
1 parent 985fa01 commit 247eea2

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

tests/utils/get-element-type.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
11
const {getElementType} = require('../../lib/utils/get-element-type')
2+
const {mockJSXAttribute, mockJSXOpeningElement} = require('./helpers')
3+
24
const mocha = require('mocha')
35
const describe = mocha.describe
46
const it = mocha.it
57
const expect = require('chai').expect
68

7-
function mockJSXAttribute(prop, propValue) {
8-
return {
9-
type: 'JSXAttribute',
10-
name: {
11-
type: 'JSXIdentifier',
12-
name: prop,
13-
},
14-
value: {
15-
type: 'Literal',
16-
value: propValue,
17-
},
18-
}
19-
}
20-
21-
function mockJSXOpeningElement(tagName, attributes = []) {
22-
return {
23-
type: 'JSXOpeningElement',
24-
name: {
25-
type: 'JSXIdentifier',
26-
name: tagName,
27-
},
28-
attributes,
29-
}
30-
}
31-
329
function mockSetting(componentSetting = {}) {
3310
return {
3411
settings: {

tests/utils/helpers.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function mockJSXAttribute(prop, propValue) {
2+
return {
3+
type: 'JSXAttribute',
4+
name: {
5+
type: 'JSXIdentifier',
6+
name: prop,
7+
},
8+
value: {
9+
type: 'Literal',
10+
value: propValue,
11+
},
12+
}
13+
}
14+
15+
function mockJSXOpeningElement(tagName, attributes = []) {
16+
return {
17+
type: 'JSXOpeningElement',
18+
name: {
19+
type: 'JSXIdentifier',
20+
name: tagName,
21+
},
22+
attributes,
23+
}
24+
}
25+
26+
module.exports = {mockJSXAttribute, mockJSXOpeningElement}

0 commit comments

Comments
 (0)