typescript zippy.component.spec.ts
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript zippy.component.spec.ts相关的知识,希望对你有一定的参考价值。
import { ZippyComponent } from './zippy.component';
import { createHostComponentFactory, SpectatorWithHost } from '@netbasal/spectator';
import { Component } from '@angular/core';
describe('ZippyComponent', () => {
let host: SpectatorWithHost<ZippyComponent>;
const createHost = createHostComponentFactory(ZippyComponent);
it('should display the title', () => {
host = createHost(`<zippy title="Zippy title"></zippy>`);
expect(host.query('.zippy__title')).toHaveText(( text ) => 'Zippy title');
});
it('should display the content', () => {
host = createHost(`<zippy title="Zippy title">Zippy content</zippy>`);
host.click('.zippy__title');
expect(host.query('.zippy__content')).toHaveText('Zippy content');
});
it('should display the "Open" word if closed', () => {
host = createHost(`<zippy title="Zippy title">Zippy content</zippy>`);
expect(host.query('.arrow')).toHaveText('Open');
expect(host.query('.arrow')).not.toHaveText('Close');
});
it('should display the "Close" word if open', () => {
host = createHost(`<zippy title="Zippy title">Zippy content</zippy>`);
host.click('.zippy__title');
expect(host.query('.arrow')).toHaveText('Close');
expect(host.query('.arrow')).not.toHaveText('Open');
}
);
it('should be closed by default', () => {
host = createHost(`<zippy title="Zippy title"></zippy>`);
expect('.zippy__content').not.toExist();
});
it('should toggle the content', () => {
host = createHost(`<zippy title="Zippy title"></zippy>`);
host.click('.zippy__title');
expect(host.query('.zippy__content')).toExist();
host.click('.zippy__title');
expect('.zippy__content').not.toExist();
});
});
以上是关于typescript zippy.component.spec.ts的主要内容,如果未能解决你的问题,请参考以下文章
TypeScript入门五:TypeScript的接口
TypeScript系列教程--初探TypeScript
TypeScript入门三:TypeScript函数类型
typescript使用 TypeScript 开发 Vue 组件
认识 TypeScript
Learining TypeScript TypeScript 简介