스텐실
Stencil은 재사용 가능하고 확장 가능한 컴포넌트 라이브러리를 구축하기 위한 라이브러리입니다. WebdriverIO와 브라우저 러너를 사용하여 실제 브라우저에서 직접 Stencil 컴포넌트를 테스트할 수 있습니다.
설정
Stencil 프로젝트에서 WebdriverIO를 설정하려면 컴포넌트 테스팅 문서의 지침을 따르세요. 러너 옵션에서 프리셋으로 stencil
을 선택하세요. 예:
// wdio.conf.js
export const config = {
// ...
runner: ['browser', {
preset: 'stencil'
}],
// ...
}
정보
React나 Vue와 같은 프레임워크와 함께 Stencil을 사용하는 경우, 해당 프레임워크의 프리셋을 유지해야 합니다.
다음 명령으로 테스트를 시작할 수 있습니다:
npx wdio run ./wdio.conf.ts
테스트 작성하기
다음과 같은 Stencil 컴포넌트가 있다고 가정해 봅시다:
./components/Component.tsx
import { Component, Prop, h } from '@stencil/core'
@Component({
tag: 'my-name',
shadow: true
})
export class MyName {
@Prop() name: string
normalize(name: string): string {
if (name) {
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase()
}
return ''
}
render() {
return (
<div class="text">
<p>Hello! My name is {this.normalize(this.name)}.</p>
</div>
)
}
}
render
테스트에서 @wdio/browser-runner/stencil
의 render
메서드를 사용하여 컴포넌트를 테스트 페이지에 연결합니다. 컴포넌트와 상호 작용하기 위해서는 실제 사용자 상호 작용에 더 가까운 WebdriverIO 명령을 사용하는 것이 좋습니다. 예:
app.test.tsx
import { expect } from '@wdio/globals'
import { render } from '@wdio/browser-runner/stencil'
import MyNameComponent from './components/Component.tsx'
describe('Stencil Component Testing', () => {
it('should render component correctly', async () => {
await render({
components: [MyNameComponent],
template: () => (
<my-name name={'stencil'}></my-name>
)
})
await expect($('.text')).toHaveText('Hello! My name is Stencil.')
})
})