Ejemplo n.º 1
0
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { MywebsiteAppComponent } from '../app/mywebsite.component';

beforeEachProviders(() => [MywebsiteAppComponent]);

describe('App: Mywebsite', () => {
  it('should create the app',
      inject([MywebsiteAppComponent], (app: MywebsiteAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'My Website\'',
      inject([MywebsiteAppComponent], (app: MywebsiteAppComponent) => {
    expect(app.title).toEqual('My Website');
  }));
});

describe('my own test', function(){

  it('number schould be positive',
    inject([MywebsiteAppComponent], (app: MywebsiteAppComponent) => {
      expect(app).toBeGreaterThan(-1);
    }));

})
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { CliProjAppComponent } from '../app/cli-proj.component';

beforeEachProviders(() => [CliProjAppComponent]);

describe('App: CliProj', () => {
  it('should create the app',
      inject([CliProjAppComponent], (app: CliProjAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'cli-proj works!\'',
      inject([CliProjAppComponent], (app: CliProjAppComponent) => {
    expect(app.title).toEqual('cli-proj works!');
  }));
});
import {beforeEachProviders, describe, expect, it, inject} from '@angular/core/testing';
import {PeriscopeAppComponent} from '../app/periscope.component';

beforeEachProviders(() => [PeriscopeAppComponent]);

describe('App: Periscope', () => {
  it('should create the app', inject([PeriscopeAppComponent], (app: PeriscopeAppComponent) => {
       expect(app).toBeTruthy();
     }));
});
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { GithubInfoAppComponent } from '../app/github-info.component';

beforeEachProviders(() => [GithubInfoAppComponent]);

describe('App: GithubInfo', () => {
  it('should create the app',
      inject([GithubInfoAppComponent], (app: GithubInfoAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'github-info works!\'',
      inject([GithubInfoAppComponent], (app: GithubInfoAppComponent) => {
    expect(app.title).toEqual('github-info works!');
  }));
});
Ejemplo n.º 5
0
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { CashFlowAppComponent } from '../app/cash-flow.component';

beforeEachProviders(() => [CashFlowAppComponent]);

describe('App: CashFlow', () => {
  it('should create the app',
      inject([CashFlowAppComponent], (app: CashFlowAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'cash-flow works!\'',
      inject([CashFlowAppComponent], (app: CashFlowAppComponent) => {
    expect(app.title).toEqual('cash-flow works!');
  }));
});
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { AngularObservableAppComponent } from '../app/angular-observable.component';

beforeEachProviders(() => [AngularObservableAppComponent]);

describe('App: AngularObservable', () => {
  it('should create the app',
      inject([AngularObservableAppComponent], (app: AngularObservableAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'angular-observable works!\'',
      inject([AngularObservableAppComponent], (app: AngularObservableAppComponent) => {
    expect(app.title).toEqual('angular-observable works!');
  }));
});
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { ChangeCalculatorAppComponent } from '../app/change-calculator.component';

beforeEachProviders(() => [ChangeCalculatorAppComponent]);

describe('App: ChangeCalculator', () => {
  it('should create the app',
      inject([ChangeCalculatorAppComponent], (app: ChangeCalculatorAppComponent) => {
    expect(app).toBeTruthy();
  }));

  // it('should have as title \'change-calculator works!\'',
  //     inject([ChangeCalculatorAppComponent], (app: ChangeCalculatorAppComponent) => {
  //   expect(app.title).toEqual('change-calculator works!');
  // }));
});
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { AngularPolymerDotnetAppComponent } from '../app/angular-polymer-dotnet.component';

beforeEachProviders(() => [AngularPolymerDotnetAppComponent]);

describe('App: AngularPolymerDotnet', () => {
  it('should create the app',
      inject([AngularPolymerDotnetAppComponent], (app: AngularPolymerDotnetAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'angular-polymer-dotnet works!\'',
      inject([AngularPolymerDotnetAppComponent], (app: AngularPolymerDotnetAppComponent) => {
    expect(app.title).toEqual('angular-polymer-dotnet works!');
  }));
});
import {
  beforeEachProviders,
  describe,
  expect,
  it,
  inject
} from '@angular/core/testing';
import { Ng2WorkshopAppComponent } from '../app/ng2-workshop.component';

beforeEachProviders(() => [Ng2WorkshopAppComponent]);

describe('App: Ng2Workshop', () => {
  it('should create the app',
      inject([Ng2WorkshopAppComponent], (app: Ng2WorkshopAppComponent) => {
    expect(app).toBeTruthy();
  }));

  it('should have as title \'ng2-workshop works!\'',
      inject([Ng2WorkshopAppComponent], (app: Ng2WorkshopAppComponent) => {
    expect(app.title).toEqual('ng2-workshop works!');
  }));
});
describe('Core Definition Service', () => {

  beforeEachProviders(() => {
    return [
      CoreDefinitionService,
      provide(ConfigService, {
        useValue: {
          get: function () { return 'http://*****:*****@id as definition', inject([CoreDefinitionService], (cds) => {
      spyOn(cds, 'getDefinitions').and.returnValue(Observable.of({
        'property': {
          '@id': 'hydra:property'
        }
      }));
      spyOn(cds, 'add');

      cds.loadDefinitions();

      expect(cds.add).toHaveBeenCalledWith('property', 'hydra:property', {});
    }));

    it('should reject object without @id as definition', inject([CoreDefinitionService], (cds) => {
      spyOn(cds, 'getDefinitions').and.returnValue(Observable.of({
        'cc:license': {
          '@type': '@id'
        }
      }));
      spyOn(cds, 'add');

      cds.loadDefinitions();

      expect(cds.add).not.toHaveBeenCalled();
    }));

  });

  describe('getDefinitions', () => {

    beforeEachProviders(() => {
      return [
        MockBackend,
        BaseRequestOptions,
        provide(Http, {
          useFactory: (backend, defaultOptions) => {
            return new Http(backend, defaultOptions);
          }, deps: [MockBackend, BaseRequestOptions]
        })
      ];
    });


    it('should dispatch local storage definitions', inject([CoreDefinitionService], (cds) => {
      spyOn(localStorage, 'getItem').and.returnValue('{"property":"hydra:property"}');

      const obs = cds.getDefinitions();

      expect(localStorage.getItem).toHaveBeenCalled();
      obs.subscribe(definitions => {
        expect(definitions.property).toEqual('hydra:property');
      })
    }));

    it('should dispatch context api definitions', async(
      inject([CoreDefinitionService, MockBackend, ConfigService],
        (cds, api, config) => {
          spyOn(localStorage, 'getItem').and.returnValue(null);

          api.connections.subscribe(c => {
            expect(c.request.url).toBe('http://*****:*****@context': {
                  'property': 'hydra:property'
                },
                'fakeValue': 'hydra:fakeValue'
              }
            });
            c.mockRespond(new Response(response));
          });

          const obs = cds.getDefinitions();

          obs.subscribe(definitions => {
            expect(definitions.property).toEqual('hydra:property');
            expect(definitions.fakeValue).toBeUndefined();
          });
        })));

  });

  describe('add', () => {

    let definitions: any;

    beforeEach(() => {
      definitions = {};
    });

    it('should define an enumerable property', inject([CoreDefinitionService], (cds) => {
      cds.add('property', 'hydra:property', definitions);

      expect(definitions.property).toEqual('hydra:property');
      expect(definitions.propertyIsEnumerable('property')).toBeTruthy();
    }));

    it('should define an unwritable property', inject([CoreDefinitionService], (cds) => {
      cds.add('property', 'hydra:property', definitions);

      expect(() => {
        definitions.property = 'custom:property';
      }).toThrow();
    }));

  });

});