测试角度2组件,但似乎吞下了一个承诺。我已经设置了一个内部期望,它应该总是失败(期望false为真)但它不会抛出异常并导致测试通过。有什么想法吗?
使用ng2 rc1
测试
import { it, ddescribe, expect, inject, async, beforeEachProviders } from '@angular/core/testing';
import { provide } from '@angular/core';
import {
TestComponentBuilder,
ComponentFixture
} from '@angular/compiler/testing';
import { Http, BaseRequestOptions } from '@angular/http';
import { LoginComponent } from './..';
import { MockBackend } from '@angular/http/testing';
import { UserService } from '../../';
ddescribe('LoginThing', () => {
it('should wrap content', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
console.log('Ready to run test');
return tcb.createAsync(LoginComponent)
.then((fixture: ComponentFixture<LoginComponent>) => {
console.log(fixture);
fixture.detectChanges();
var compiled = fixture.debugElement.nativeElement;
expect(compiled).toContainText('stuff');
expect(false).toBe(true);
});
})));
});
业力测试垫片
/*global jasmine, __karma__, window*/
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
__karma__.loaded = function () {
};
var distPath = '/base/.test/';
var appPath = distPath + 'app/';
function isJsFile(path) {
return path.slice(-3) == '.js';
}
function isSpecFile(path) {
return path.slice(-8) == '.spec.js';
}
function isAppFile(path) {
return isJsFile(path) && (path.substr(0, appPath.length) == appPath);
}
var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isAppFile);
// Load our SystemJS configuration.
System.config({
baseURL: distPath,
});
System.import('system.config.js').then(function(e) {
// Load and configure the TestComponentBuilder.
return Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
]).then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];
testing.setBaseTestProviders(
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
);
});
}).then(function() {
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
}).then(__karma__.start, __karma__.error);