我可以使用一些建议如何解决我面临的这个问题.为了向您解释这一点,我创建了一个主要组件:
@Component({
selector: 'main-component',
providers: [...FORM_PROVIDERS, MainService, MainQuoteComponent],
directives: [...ROUTER_DIRECTIVES, CORE_DIRECTIVES, RouterOutlet, MainQuoteComponent ],
styles: [`
agent {
display: block;
}
`],
pipes: [],
template: `
**Html hidden**
`,
bindings: [MainService],
})
@RouteConfig([
{ path: '/', name: 'Main', component: MainMenuComponent, useAsDefault: true },
{ path: '/passenger', name: 'Passenger', component: PassengerComponent },
])
@Injectable()
export class MainComponent {
bookingNumber: string;
reservation: Reservation;
profile: any;
constructor(params: RouteParams, public mainService: MainService) {
this.bookingNumber = params.get("id");
this.mainService.getReservation(this.bookingNumber).subscribe((reservation) => {
this.reservation = reservation;
});
this.profile …Run Code Online (Sandbox Code Playgroud) 我可以使用一些帮助找到解决问题的方法.当它向api发出请求时,我需要向angular2应用程序模拟一些数据,我需要做类似的事情:
$httpBackend.when('GET', '/userbookings/').respond(my json file data);
Run Code Online (Sandbox Code Playgroud)
问题是我可以在谷歌上找到所有,使用$ httpBackend用于angularJS(角度1).
有没有人知道如何在我的E2E测试中使用它(该应用程序是一个angular2 applciation)?我正试图用量角器或夜间仪表做这个(尝试过两个框架)
规格测试:
describe('Protractor Mocking bookings for angular2 site', function() {
var ngMockE2E = require('ng-mock-e2e');
var $httpBackend = ngMockE2E.$httpBackend;
beforeEach(function() {
ngMockE2E.addMockModule();
ngMockE2E.addAsDependencyForModule('myApp');
ngMockE2E.embedScript('/bower_components/angular-mocks/angular-mocks.js');
});
afterEach(function() {
ngMockE2E.clearMockModules();
});
it('Inject mock data of bookings', function() {
var EC = protractor.ExpectedConditions;
var global = require('../bin/globals.js');
// Bookings data in a json file which should be send as the response
var mockData = require('../testData.json');
browser.ignoreSynchronization = false;
$httpBackend.when('GET', '/userbookings').respond(mockData);
browser.get(global.so.enLoggedIn);
});
});
Run Code Online (Sandbox Code Playgroud)
这个测试不会起作用,因为它使用了一些angular1方式.已经展示了它,所以你可以看到我的测试看起来如何.
希望有人可以帮助我,因为很难找到一些与angular2合作的人.
在我对API应用程序进行API调用之前,我正在为我的视图制作一些测试数据.
在我的angular 2应用程序的服务中,我创建了一个如下所示的界面:
export interface amendmentBookings {
bookingNumber: string;
outboundDate: Date;
returnDate: Date;
route: string;
Passengers: string;
vehicleType: string;
}
Run Code Online (Sandbox Code Playgroud)
我还创建了一个数组,该数组必须包含此接口的类型.代码如下所示:
var bookings: amendmentBookings[] = [
{
bookingNumber: "123456789",
outboundDate:
returnDate:
route: "Dünkirchen - Dover",
vehicleType: "Car 1.85m x 4.5m",
Passengers: "1 adult and 1 child"
},
]
Run Code Online (Sandbox Code Playgroud)
如何在测试数据中插入日期?
我已尝试使用您在javascript中使用的新Date(),如下所示:
new Date("February 4, 2016 10:13:00");
Run Code Online (Sandbox Code Playgroud)
但这不起作用..
我正在尝试在wpf应用程序中使用网格行/列定义。目前,我需要在GroupBox中实现一个列表视图。在这里,我需要忽略在视图顶部设置的列定义。
行和列的定义:
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="260" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
Run Code Online (Sandbox Code Playgroud)
在这里,您看到我的rowDefinition高度为260。其中应该包含我的列表视图。问题在于它在我创建的列中,因此不会占用所有空间。是否有某种设置可以使该行忽略我设置的列?我仍然希望将这些列用于其他行。
在这里,您可以看到其外观的图片:
希望有人能帮忙,美好的一天。
我需要将一个日期字符串转换为实际日期,我可以用来比较哪些日期最早.
我的日期是这种格式"2010年1月2日"我知道我应该使用某种类型的日期格式,但不知道如何使用javascript.
这是我得到的代码:
function checkOutboundAndReturnDates(outboundDate, returnDate) {
var outboundDatetime = new Date(outboundDate);
var returnDatetime = new Date(returnDate);
var date = new Date("2017-03-25");
console.log(outboundDate);
console.log(returnDate);
console.log("Converting dates");
console.log(outboundDatetime);
console.log(returnDatetime);
console.log(date);
// String string = "January 2, 2010";
// DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
// Date date = format.parse(string);
}
Run Code Online (Sandbox Code Playgroud)
var日期正在运行,但这仅用于测试,而不是我想要的.得到了数字的一天,数字中的年份,但文本中的月份,就像我写的:
"January 2, 2010"
Run Code Online (Sandbox Code Playgroud)
更新
var outboundDateTime = moment(outboundDate, "MMMM DD, YYYY");
var returnDateTime = moment(returnDate, "MMMM DD, YYYY");
console.log(outboundDateTime.format("YYYY-MM-DD"));
console.log(returnDateTime.format("YYYY-MM-DD"));
if (outboundDateTime > returnDateTime) {
console.log("its bigger");
return …Run Code Online (Sandbox Code Playgroud) angular ×2
date ×2
datetime ×1
grid-layout ×1
groupbox ×1
javascript ×1
listview ×1
protractor ×1
typescript ×1
wpf ×1
xaml ×1