Skip to content

Commit 4867519

Browse files
webfrontzhifeieddyerburgh
authored andcommitted
fix: hasStyle to return false if name is undefined
* fix bug * add undefined style bugfix testcase * fix hasStyle function return boolean
1 parent 3c0881a commit 4867519

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/wrappers/wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default class Wrapper implements BaseWrapper {
132132

133133
const elStyle = window.getComputedStyle(this.element)[style]
134134
const mockNodeStyle = window.getComputedStyle(mockNode)[style]
135-
return elStyle === mockNodeStyle
135+
return !!(elStyle && mockNodeStyle && elStyle === mockNodeStyle)
136136
}
137137

138138
/**

test/unit/specs/mount/Wrapper/hasStyle.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ describe('hasStyle', () => {
5353
const fn = () => wrapper.hasStyle('color', undefined)
5454
expect(fn).to.throw().with.property('message', message)
5555
})
56+
57+
it('return false when the style is a invalid prop name ', () => {
58+
if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) {
59+
return
60+
}
61+
const wrapper = mount(ComponentWithStyle)
62+
expect(wrapper.find('p').hasStyle('margin-top333', '10px')).to.equal(false)
63+
})
5664
})

0 commit comments

Comments
 (0)