-
Notifications
You must be signed in to change notification settings - Fork 1
Snippets
Robert Willemelis edited this page Apr 13, 2018
·
5 revisions
[{
"context": [
"/path1/",
"/path2/"
],
"target": "https://www.domain.de/",
"secure": false
}
]
[{
"/path3/*": {
"target": "https://www.domain.de",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
},{
"/path4/*": {
"target": "https://www.domain.de",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}]
compare: (actual: any, styles: {[k: string]: string}|string) => {
let allPassed: boolean;
if (typeof styles === 'string') {
allPassed = true; //getDOM().hasStyle(actual, styles);
} else {
allPassed = Object.keys(styles).length !== 0;
Object.keys(styles).forEach(prop => {
allPassed = allPassed && true; //getDOM().hasStyle(actual, prop, styles[prop]);
});
}
return {
pass: allPassed,
get message() {
const expectedValueStr = typeof styles === 'string' ? styles : JSON.stringify(styles);
return `Expected ${actual.outerHTML} ${!allPassed ? ' ' : 'not '}to contain the
CSS ${typeof styles === 'string' ? 'property' : 'styles'} "${expectedValueStr}"`;
}
};
}
return {
compare: buildError(false), negativeCompare: buildError(true)};
function buildError(isNot: boolean) {
return function (actual: any, className: string) {
return {
pass: _.hasClass(actual, className) == !isNot,
get message() {
return `
Expected ${actual.outerHTML} ${isNot ? 'not ' : ''}
to contain the CSS class '${className}'
`;
}
};
};
}
const result: jasmine.CustomMatcherResult = {
pass: false,
message: ''
};
for (let i = 0 ; i < actual.length; i++) {
if (actual[i] !== expected[i]) {
result.message = 'Wrong sequence on #' + (i + 1);
return result;
}
}
result.pass = true;
return result
xdescribe('xxx', () => {
afterEach(inject([HttpTestingController], (backend: HttpTestingController) => {
backend.verify();
}));
// it('should make a request via http', async() => {
it(`Xshould send an expected login request`, async(inject([
// HttpClientFeatureService,
HttpTestingController],
(
// service: HttpClientFeatureService,
backend: HttpTestingController) => {
const fixture = TestBed.createComponent(ContactComponent);
const app = fixture.debugElement.componentInstance;
const control = component.form.get('email');
const form = component.form;
const expectedResults = [{ ok: 0}];
const mockResponse = new Response(new ResponseOptions({ body: { data: expectedResults } }));
const mockHttp = jasmine.createSpyObj('http', ['get']);
mockHttp.get.and.returnValue(Observable.of(mockResponse));
// const service = new xyService(mockHttp as any);
// let actualResults;
// service.search('mysearch').subscribe((value) => { actualResults = value; });
component.onSubmit();
expect(mockHttp.get).toHaveBeenCalledWith('/api');
// expect(actualResults).toEqual(expectedResults);
})));
xit(`should send an expected login request`, async(inject([
// HttpClientFeatureService,
HttpTestingController],
(
// service: HttpClientFeatureService,
backend: HttpTestingController) => {
// service.login('foo', 'bar').subscribe();
// component.form.controls.first_name.setValue('xxx');
// component.form.controls.last_name.setValue('xxxx');
// component.form.controls.email.setValue('xxxx@xxx.de');
// component.form.controls.message.setValue('xxx');
// component.form.controls.company.setValue('xxx');
// component.form.controls.phone.setValue('012');
// component.form.controls.salutation.setValue('Frau');
// component.form.controls.subject.setValue('xxx');
// component.onSubmit();
const request = backend.expectOne('/api');
request.flush({ ok: 1});
// console.log('component.responseApi');
// console.log(component.responseApi);
// backend.verify();
// backend.expectOne((req: HttpRequest<any>) => {
// const body = new HttpParams({ fromString: req.body });
// console.log(req.url);
// // if(req.url === '/api'){
// // return { ok: 0}
// // }
// return req.url === '/api';
// }, '{ ok: 1}');
// return req.url === 'auth/login'
// && req.method === 'POST'
// && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded'
// && body.get('user') === 'foo'
// && body.get('password') === 'bar';
// }, `POST to 'auth/login' with form-encoded user and password`);
})));
// beforeEach(() => {
// httpClient = TestBed.get(HttpClient);
// spyOn(httpClient, 'post').and.callFake(function(arg){
// console.log(arg);
// if (!arg) {
// return Observable.throw({status: 404}); // throw error
// } else if (arg.indexOf('duplicated') >= 0) {
// return Observable.of('duplicate');
// } else if (arg.indexOf('neu') >= 0) {
// return Observable.of('ok');
// } else {
// return Observable.of('someError');
// }
// });
// });
xit('onSubmit: xxx - default', async(() => {
const fixture = TestBed.createComponent(ContactComponent);
const app = fixture.debugElement.componentInstance;
const control = component.form.get('email');
const form = component.form;
// this.form.controls.first_name.value = 'x';
// this.form.controls.last_name.value = 'x';
// this.form.controls.email.value = 'xxx@xxx.de';
// this.form.controls.message.value = 'x';
// this.form.controls.company.value = 'x';
// this.form.controls.phone.value = '23';
// this.form.controls.salutation.value = 'Mann';
// this.form.controls.subject.value = 'x';
console.log(app);
console.log(control);
console.log(form);
console.log(component)
app.email = 'invalid';
app.onSubmit({ form: { valid: true, invalid: false}});
expect(app.optivoStatus).toEqual('error');
}));
xit('onSubmit: xxx - default', async(() => {
const fixture = TestBed.createComponent(ContactComponent);
const app = fixture.debugElement.componentInstance;
app.model.email = 'neu@gmx.de';
app.onSubmit({ form: { valid: true, invalid: false}});
expect(app.model.optivoStatus).toEqual('ok');
}));
xit('onSubmit: xxx - default', async(() => {
const fixture = TestBed.createComponent(ContactComponent);
const app = fixture.debugElement.componentInstance;
app.model.email = 'duplicated@gmx.de';
app.onSubmit({ form: { valid: true, invalid: false}});
expect(app.model.optivoStatus).toEqual('duplicate');
}));
});
});