Tôi nhận được lỗi này:góc 2 & Jasmine: Lỗi: Vui lòng gọi "TestBed.compileComponents" trước khi thử nghiệm của bạn
Error: This test module uses the component MessagesComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test.
Khi cố gắng để chạy thử nghiệm đơn giản này kiễu góc 2 & Jasmine Test:
let comp: MessagesComponent;
let fixture: ComponentFixture<MessagesComponent>;
describe('MessagesComponent',() => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ MessagesComponent ],
providers: [ {provide: DataService, useValue: {} } ]
})
.compileComponents(); // compile template and css
fixture = TestBed.createComponent(MessagesComponent);
comp = fixture.componentInstance;
});
it('example',() => {
expect("true").toEqual("true");
});
});
tôi nghĩ rằng nó có thể là do một cái gì đó với cấu hình thử nghiệm webpack của tôi:
'use strict';
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'inline-source-map',
module: {
loaders: [
{ loader: 'raw', test: /\.(css|html)$/ },
{ exclude: /node_modules/, loader: 'ts', test: /\.ts$/ }
]
},
resolve: {
extensions: ['', '.js', '.ts'],
modulesDirectories: ['node_modules'],
root: path.resolve('.', 'src')
},
tslint: {
emitErrors: true
}
};
Tôi có nên thay đổi phương thức (...) theo bất kỳ cách nào không? – commonSenseCode
Chỉ khi 'it()' làm bất cứ điều gì không đồng bộ, ví dụ, nếu nó tìm nạp dữ liệu từ một dịch vụ. Hoàn toàn ổn nếu 'beforeEach()' cần phải không đồng bộ nhưng 'it()' thì không. – pe8ter
lạ Tôi hỏi vì tôi giữ gettin cùng một thông báo lỗi như được đăng trong câu hỏi ban đầu của tôi nhưng ít nhất bây giờ nó nói 1 của 1 thất bại – commonSenseCode