2017-01-02 86 views
0

我正在學習Angular 2測試,並且我收到了一個目前對我無意義的錯誤。'expect'在沒有當前規範的情況下使用

'expect' was used when there was no current spec,

測試:

import {ExperimentsComponent} from "./experiments.component"; 
import {StateService} from "../common/state.service"; 
import {ExperimentsService} from "../common/experiments.service"; 

describe('experiments.component title and body should be correct',() => { 

    let stateService = StateService; 
    let experimentService = ExperimentsService; 

    let app = new ExperimentsComponent(new stateService, new experimentService); 

    expect(app.title).toBe('Experiments Page'); 
    expect(app.body).toBe('This is the about experiments body'); 

}); 

組件:

import {Component, OnInit} from "@angular/core"; 
import {Experiment} from "../common/experiment.model"; 
import {ExperimentsService} from "../common/experiments.service"; 
import {StateService} from "../common/state.service"; 


@Component({ 
    selector: 'experiments', 
    template: require('./experiments.component.html'), 

}) 
export class ExperimentsComponent implements OnInit { 
    title: string = 'Experiments Page'; 
    body: string = 'This is the about experiments body'; 
    message: string; 
    experiments: Experiment[]; 

    constructor(private _stateService: StateService, 
       private _experimentsService: ExperimentsService) { 
    } 

    ngOnInit() { 
     this.experiments = this._experimentsService.getExperiments(); 
     this.message = this._stateService.getMessage(); 
    } 

    updateMessage(m: string): void { 
     this._stateService.setMessage(m); 
    } 
} 

最後,我想測試在實踐應用中的所有功能。但截至目前,我只獲得由angular-cli生成的測試。

從我從文檔中讀取的內容看起來正確,我在做什麼。內it()陳述

回答

1

expect()語句出現這樣的:

describe('ExperimentsComponent',() => { 
... 
    it('should be created',() => { 
    expect(component).toBeTruthy(); 
    }); 
... 
} 

這就是錯誤是如何被讀取:

ExperimentsComponent應該創建創建是假

你似乎有describeit參數混淆

相關問題