Skip to content

Commit 34f8b18

Browse files
committed
Add missing unit test for getStaticPropertyName
1 parent e071d2a commit 34f8b18

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/lib/utils/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,48 @@ describe('getComputedProperties', () => {
121121
assert.ok(computedProperties[0].value)
122122
})
123123
})
124+
125+
describe('getStaticPropertyName', () => {
126+
let node
127+
128+
const parse = function (code) {
129+
return babelEslint.parse(code).body[0].declarations[0].init
130+
}
131+
132+
it('should parse property expression with identifier', () => {
133+
node = parse(`const test = { computed: { } }`)
134+
135+
const parsed = utils.getStaticPropertyName(node.properties[0])
136+
assert.ok(parsed === 'computed')
137+
})
138+
it('should parse property expression with literal', () => {
139+
node = parse(`const test = { ['computed'] () {} }`)
140+
141+
const parsed = utils.getStaticPropertyName(node.properties[0])
142+
assert.ok(parsed === 'computed')
143+
})
144+
it('should parse property expression with template literal', () => {
145+
node = parse(`const test = { [\`computed\`] () {} }`)
146+
147+
const parsed = utils.getStaticPropertyName(node.properties[0])
148+
assert.ok(parsed === 'computed')
149+
})
150+
it('should parse identifier', () => {
151+
node = parse(`const test = { computed: { } }`)
152+
153+
const parsed = utils.getStaticPropertyName(node.properties[0].key)
154+
assert.ok(parsed === 'computed')
155+
})
156+
it('should parse literal', () => {
157+
node = parse(`const test = { ['computed'] () {} }`)
158+
159+
const parsed = utils.getStaticPropertyName(node.properties[0].key)
160+
assert.ok(parsed === 'computed')
161+
})
162+
it('should parse template literal', () => {
163+
node = parse(`const test = { [\`computed\`] () {} }`)
164+
165+
const parsed = utils.getStaticPropertyName(node.properties[0].key)
166+
assert.ok(parsed === 'computed')
167+
})
168+
})

0 commit comments

Comments
 (0)