Skip to content

Commit 8575411

Browse files
committed
feat(as): added tests for as polymporphic prop
1 parent 1d77a10 commit 8575411

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/test/as.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Vue from 'vue'
2+
import expect from 'expect'
3+
import { resetStyled, expectCSSMatches } from './utils'
4+
5+
let styled
6+
7+
describe('"as" polymorphic prop', () => {
8+
beforeEach(() => {
9+
styled = resetStyled()
10+
})
11+
12+
it('should render "as" polymorphic prop element', () => {
13+
const Base = styled.div`
14+
color: blue;
15+
`
16+
const b = new Vue({
17+
render: (h) => h(Base, {
18+
props: {
19+
as: 'button'
20+
}
21+
})
22+
}).$mount()
23+
expect(b.$el.tagName.toLowerCase()).toEqual('button')
24+
})
25+
26+
27+
it('should append base class to new components composing lower level styled components', () => {
28+
const Base = styled.div`
29+
color: blue;
30+
`
31+
const Composed = styled(Base, {
32+
bg: String,
33+
})`
34+
background: ${props => props.bg};
35+
`
36+
37+
const b = new Vue(Base).$mount()
38+
const c = new Vue({
39+
render: (h) => h(Composed, {
40+
props: {
41+
bg: 'yellow',
42+
as: 'dialog'
43+
}
44+
})
45+
}).$mount()
46+
47+
expect(c.$el.tagName.toLowerCase()).toEqual('dialog')
48+
expect(c.$el._prevClass.includes(b.$el._prevClass)).toBeTruthy()
49+
expectCSSMatches('.a{color: blue;} .b{background:yellow;}')
50+
})
51+
})

src/test/props.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ describe('props', () => {
6060
const vm = new Vue(Themed).$mount()
6161
expectCSSMatches('.a {color: blue;}')
6262
})
63+
64+
it()
6365
})

0 commit comments

Comments
 (0)