Beispiel #1
0
  it('should login', inject([TestComponentBuilder], fakeAsync((tcb:TestComponentBuilder) => {
    let fixture;
    tcb
      // https://github.com/angular/angular/issues/2835
      .overrideTemplate(TaLogin, `
        <form>
          <input type="text" #username>
          <button (click)="loginSubmit(username)">Find user</button>
        </form>
      `)
      .createAsync(TaLogin).then((rootFixture) => {
        fixture = rootFixture;
      });

    tick();

    let componentInstance = fixture.componentInstance;
    let element = fixture.nativeElement;
    let username;

    componentInstance.login.subscribe((value) => {
      username = value;
    });

    element.querySelector('input').value = 'cironunes';
    element.querySelector('button').click();
    tick();
    expect(username).toBe('cironunes');
  })));
      tcb.createAsync(DemoFormWithEvents).then((fixture) => {
        let el = fixture.debugElement.nativeElement;
        let input = fixture.debugElement.query(By.css("input")).nativeElement;
        let form = fixture.debugElement.query(By.css("form")).nativeElement;
        fixture.detectChanges();

        input.value = '';
        dispatchEvent(input, 'input');
        fixture.detectChanges();
        tick();

        // no value on sku field, all error messages are displayed
        let msgs = el.querySelectorAll('.ui.error.message');
        expect(msgs[0]).toHaveText('SKU is invalid');
        expect(msgs[1]).toHaveText('SKU is required');

        // displays no errors when sku has a value
        input.value = 'XYZ';
        dispatchEvent(input, 'input');
        fixture.detectChanges();
        tick()

        msgs = el.querySelectorAll('.ui.error.message');
        expect(msgs.length).toEqual(0);

        fixture.detectChanges();
        dispatchEvent(form, 'submit');
        tick();

        // checks for the form submitted message
        expect(fakeConsole._logs).toContain('you submitted value: XYZ');
      });
      createComponent(tcb).then((fixture) => {
        input.value = 'ABC';
        dispatchEvent(input, 'input');
        tick();

        fixture.detectChanges();
        dispatchEvent(form, 'submit');
        tick();

        expect(fakeConsole._logs).toContain('you submitted value: ABC');
      });
                    .then((controlsInstance: PaginationControlsCmp) => {
                        testCmpInstance.config.currentPage = 1;
                        fixture.detectChanges();
                        tick();

                        expect(controlsInstance.api.isLastPage()).toBe(false);

                        testCmpInstance.config.currentPage = 10;
                        fixture.detectChanges();
                        tick();

                        expect(controlsInstance.api.isLastPage()).toBe(true);
                    });
  it('should accept pin (with fakeAsync)', inject([TestComponentBuilder], fakeAsync((tcb) => {
    var fixture;
    tcb.createAsync(GreetingComponent).then((rootFixture) => {
      fixture = rootFixture });
    tick();

    var compiled = fixture.debugElement.nativeElement;
    compiled.querySelector('button').click();

    tick();
    fixture.detectChanges();
    expect(compiled.querySelector('h3')).toHaveText('Status: Welcome!');
  })));
      it('should load operations and schema', inject([], fakeAsync(() => {
        mockBackend.connections.subscribe(c => {
          expect(c.request.url).toBe('http://*****:*****@id': 'http://schema.org/Person'},
                {'@id': 'http://schema.org/BlogPosting'},
                {'@id': '#Entrypoint'},
                {'@id': '#ConstraintViolation'},
                {'@id': '#ConstraintViolationList'}
              ]
            }
          });
          c.mockRespond(new Response(response));
        });

        spyOn(schemaService, '_loadCollectionOperations');
        spyOn(schemaService, '_loadSingleOperations');
        spyOn(schemaService, '_loadSchema');

        schemaService._loadDocumentation();
        tick();

        expect(schemaService._loadCollectionOperations).toHaveBeenCalled();
        expect(schemaService._loadSingleOperations).toHaveBeenCalled();
        expect(schemaService._loadSchema).toHaveBeenCalled();
      })));
Beispiel #7
0
    it('should set the user', inject([Ng2TestsApp], fakeAsync((app: Ng2TestsApp) => {
      app.findUser('nonexistent');
      tick();

      expect(app.user).toBe(null);
      expect(app.msg).toBe('User not found');
    })));
      fakeAsync((tasksService, mockBackend) => {

        mockBackend.connections.subscribe( conn => {

          chai.expect(conn.request.url).to.be.oneOf([
            'http://ngcourse.herokuapp.com/api/v1/tasks',
            'http://ngcourse.herokuapp.com/api/v1/tasks/1'
          ]);
          chai.expect(conn.request.method).to.be.oneOf([
            RequestMethod.Get,
            RequestMethod.Post,
            RequestMethod.Delete,
            RequestMethod.Put
          ]);

          if (conn.request.url ===
            'http://ngcourse.herokuapp.com/api/v1/tasks' &&
            conn.request.method === RequestMethod.Get) {
              let response = new ResponseOptions({body: mockTasksResponse});
              conn.mockRespond(new Response(response));
              return;
          }

          let response = new ResponseOptions({body: mockResponseBody});
          conn.mockRespond(new Response(response));
        });

        tasksService.fetch();
        tick();
        callback(tasksService);
      }
      createComponent(tcb).then((fixture) => {
        input.value = 'XYZ';
        dispatchEvent(input, 'input');
        tick();

        expect(fakeConsole._logs).toContain('form changed to: [object Object]');
      });
                    .then((controlsInstance: PaginationControlsCmp) => {
                        spyOn(testCmpInstance, 'pageChanged');
                        controlsInstance.api.next();
                        tick();

                        expect(testCmpInstance.pageChanged).toHaveBeenCalledWith(3);
                    });