【发布时间】:2023-03-16 16:38:01
【问题描述】:
这是我第一次使用 Jasmine 制作项目,我正在学习教程,但马上就遇到了问题。
我已经安装了 jasmine-node、typings 和 typescript。我也跑了:
typings install dt~jasmine --save-dev --global
对于 Jasmine 打字稿。
现在我的 ./spec 文件夹中有一个测试文件,如下所示:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DatePickerComponent } from '../src/components/via-datepicker.component';
import * as moment from 'moment';
const Moment: any = (<any>moment).default || moment;
describe('DatePickerComponent', () => {
let component: DatePickerComponent;
let fixture: ComponentFixture<DatePickerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DatePickerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DatePickerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should open when clicked', () => {
fixture.debugElement.nativeElement.querySelector('body').click();
fixture.whenStable().then(() => {
expect(component.opened);
});
component.close();
});
describe('While open', () => {
beforeEach(() => {
component.open();
});
describe('Pressing the "Today\'s date" button', () => {
it('should set the value of the picker to the current date and close it', () => {
fixture.debugElement.nativeElement.querySelector('.datepicker-buttons button').click();
expect(Moment().isSame(component.value, 'day') && Moment().isSame(component.value, 'month'));
expect(!component.opened);
});
});
describe('Clicking on a date', () => {
it('should change the value of the picker and close it', () => {
let oldValue: any = component.value;
fixture.debugElement.nativeElement.querySelectorAll('.day')[10].click();
expect(!component.opened);
expect(!component.value.isSame(oldValue));
});
});
});
});
但是当我运行这个命令时:
node_modules/jasmine-node/bin/jasmine-node spec
我得到这个结果:
Finished in 0 seconds
0 tests, 0 assertions, 0 failures, 0 skipped
很明显我的测试文件被忽略了。或者也许我错过了一些图书馆?如果是这种情况,我会收到错误消息吗?这里的主要问题是我没有得到太多关于问题所在的方向,除了 Jasmine 由于某种原因似乎没有“看到”测试文件。
只是想推进我的项目。任何建议将不胜感激。
【问题讨论】:
标签: node.js angular typescript jasmine