.then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     // setTimeout(() => {
       expect(_kmq).toContain(['identify', 'testUser']);
       resolve();
     // });
   });
 });
 return tcb.createAsync(ngBsTablePaging).then((fixture:ComponentFixture,done)=>{
     fixture.componentInstance.pageSize = 100;
     fixture.componentInstance.totalRecords = 500;
     fixture.componentInstance.currPage = 4;
     fixture.detectChanges();
     let pgBtnEle = fixture.nativeElement.querySelectorAll('.pagination li');
     expect(pgBtnEle.length).toBe(7);
     expect(pgBtnEle[4].className).toContain('active');
 })
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     // setTimeout(() => {
       expect(_kmq).toContain(['record', 'do', { category: 'cat' }]);
       resolve();
     // });
   });
 });
 return prep.then((fixture: ComponentFixture) => {
   fixture.detectChanges();
   let debug = fixture.debugElement.query(By.css('md-sidenav'));
   return {
     fixture: fixture,
     component: debug.componentInstance,
     debug: debug
   };
 }).catch(console.error.bind(console));
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(_kmq).toContain(['set', { userId: '1', firstName: 'John', lastName: 'Doe' }]);
       resolve();
     });
   });
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(analytics.identify).toHaveBeenCalledWith('1', { userId: '1', firstName: 'John', lastName: 'Doe' });
       resolve();
     }, 100);
   });
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(_kmq).toContain(['record', 'Pageview', { 'Page': '/abc' }]);
       resolve();
     });
   });
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(EventSpy).toHaveBeenCalledWith({ action: 'InitiateSearch', properties: { category: 'Search', eventType: 'click' } });
       resolve();
     });
   });
 });
 return tcb.createAsync(UserListItemComponent).then((fixture: ComponentFixture) => {
   fixture.componentInstance.id = '50';
   fixture.componentInstance.username = 'barretodavid';
   fixture.componentInstance.email = 'barretollano@gmail.com';
   fixture.detectChanges();
   let compiled = fixture.debugElement.nativeElement;
   expect(compiled.querySelector('span.username')).toHaveText('Username: barretodavid');
   expect(compiled.querySelector('span.email')).toHaveText('Email: barretollano@gmail.com');
 });
                .then((fixture: ComponentFixture) => {
                    let instance: TestCmp = fixture.componentInstance;
                    instance.config.itemsPerPage = 1;
                    instance.config.currentPage = 50;
                    fixture.detectChanges();
                    let expected = ['1', '...', '48', '49', '50', '51', '52', '...', '100'];

                    expect(getPageLinkItems(fixture)).toEqual(expected);
                });
 .then((_fixture: ComponentFixture) => {
     fixture = _fixture;
     testCmpInstance = _fixture.componentInstance;
     testCmpInstance.config.currentPage = 2;
     let controlsInstance: PaginationControlsCmp = _fixture
         .debugElement.query(By.css('pagination-controls')).componentInstance;
     _fixture.detectChanges();
     return controlsInstance;
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     // setTimeout(() => {
       expect(analytics.track).toHaveBeenCalledWith('do', { category: 'cat' });
       resolve();
     // });
   });
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(analytics.page).toHaveBeenCalledWith('/abc');
       resolve();
     });
   });
 });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     setTimeout(() => {
       expect(_gaq).toContain(['_trackPageview', '']);
       expect(ga).toHaveBeenCalledWith('send', 'pageview', '');
       resolve();
     });
   });
 });
        it('should provide the child toast component if it was created via service', () => {
            const element = componentFixture.nativeElement;
            expect(componentFixture.componentInstance.toasts.length).toBe(0);
            expect(element.querySelector('#toasty').children.length).toBe(0);

            componentFixture.componentInstance.toasts.push(toast1);
            componentFixture.detectChanges();
            expect(element.querySelector('#toasty').children.length).toBe(1);
            expect(element.querySelector('#toasty').children[0].tagName).toBe('NG2-TOAST');
        });
 .then((_) => {
   fixture.detectChanges();
   return new Promise((resolve) => {
     expect(EventSpy).not.toHaveBeenCalled();
     angulartics2.eventTrack.subscribe((x: any) => EventSpy(x));
     compiled = fixture.debugElement.nativeElement.children[0];
     compiled.click();
     resolve();
   });
 })
 createComponent(tcb).then((fixture: ComponentFixture) => {
   usernameInput.value = 'barretodavid';
   emailInput.value = 'barretollano@gmail.com';
   dispatchEvent(usernameInput, 'input');
   dispatchEvent(emailInput, 'input');
   tick();
   fixture.detectChanges();
   let data = element.querySelector('.submit-data');
   expect(data).toHaveText('Value to submit: barretodavid, barretollano@gmail.com');
 });
      .createAsync(TestComponent).then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        rootRenderer.executeCommands();
        mock.clearLogs();

        var target = fixture.elementRef.nativeElement.children[0].children[0];
        fireEvent('topTouchStart', target, 0, [[50, 0]]);
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'COMMAND+3+hotspotUpdate+50,0,COMMAND+3+setPressed+true');
        mock.clearLogs();

        fireEvent('topTouchEnd', target, 40, [[100, 0]]);
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'COMMAND+3+hotspotUpdate+100,0,COMMAND+3+setPressed+false');
      });
      .createAsync(TestComponent).then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        rootRenderer.executeCommands();
        mock.clearLogs();

        var target = fixture.elementRef.nativeElement.children[0].children[0];
        fireEvent('topTouchStart', target, 0, [[0, 0]]);
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'UPDATE+3+native-view+{"opacity":0.5}');
        mock.clearLogs();

        fireEvent('topTouchEnd', target, 40, [[100, 0]]);
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'UPDATE+3+native-view+{"opacity":1}');
      });
            return tcb.createAsync(LabelWithValue).then((fixture:ComponentFixture) => {

                const componentInstance:LabelWithValue = fixture.debugElement.componentInstance;
                componentInstance.label = "testLabel";
                componentInstance.value = "testValue";
                fixture.detectChanges();

                const nativeElement:HTMLElement = fixture.debugElement.nativeElement;
                const text = nativeElement.textContent.replace(/\n/g,"").replace(/ /g,"");
                expect(text).toEqual("testLabeltestValue");
            });
Example #21
0
  it('should have a title', () => {
    // given a component instance
    let appCmp = fixture.componentInstance;

    // when we trigger the change detection
    fixture.detectChanges();

    // then we should have a name
    let element = fixture.nativeElement;
    expect(element.querySelector('h1')).toHaveText('Hello, Angular2!');
  });
      .createAsync(TestComponent).then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'CREATE+2+test-cmp+{},CREATE+3+native-view+{},ATTACH+1+2+0,ATTACH+2+3+0');

        mock.clearLogs();
        fixture.debugElement.componentInstance.view.setPressed(true);
        expect(mock.commandLogs.toString()).toEqual(
          'COMMAND+3+setPressed+true');
      });
Example #23
0
        (componentFixture: ComponentFixture) => {
          const element = componentFixture.nativeElement;
          const inputs = element.querySelectorAll('input');

          componentFixture.detectChanges();

          const task = mockTasksService.getById(_id);
          chai.expect(inputs[0].value).to.equal(task._id);
          chai.expect(inputs[1].value).to.equal(task.owner);
          chai.expect(inputs[2].value).to.equal(task.description);
        }
                .then((fixture: ComponentFixture) => {
                    let instance: TestCmp = fixture.componentInstance;
                    let controlsInstance: PaginationControlsCmp = fixture
                        .debugElement.query(By.css('pagination-controls')).componentInstance;
                    spyOn(instance, 'pageChanged');

                    instance.collection.push('item 101');
                    instance.config.currentPage = 11;
                    fixture.detectChanges();

                    expect(controlsInstance.getCurrent()).toBe(11);

                    instance.collection.pop();
                    fixture.detectChanges();
                    tick();
                    fixture.detectChanges();
                    tick();

                    expect(instance.pageChanged).toHaveBeenCalledWith(10);
                });
    it('should add todo successfully', () => {
        todolistCmp.todo = new Todo('test', true);
        todolistCmp.addTodo();
        testFixture.detectChanges();

        let items = todoCompiled.querySelectorAll('.list-group-item');
        expect(items.length).toEqual(3);

        let item = items[items.length - 1];
        expect(item.querySelector('label').textContent).toEqual(' test');
        expect(item.querySelector('input[type="checkbox"]').checked).toBeTruthy();
    });
        testComponentBuilder.createAsync(WeatherComponent).then((fixture: ComponentFixture) => {

            let element = fixture.nativeElement;
            let component: WeatherComponent = fixture.componentInstance;

            component.weather = { place: "New York", humidity: "44", temperature: "57" };

            fixture.detectChanges();

            expect(element.querySelector("h3").innerHTML).toBe("Current weather in New York:");
            expect(element.querySelector("li:nth-of-type(1)").innerHTML).toBe("Temparature: 57");
            expect(element.querySelector("li:nth-of-type(2)").innerHTML).toBe("Humidity: 44");
            done();
        });
Example #27
0
        (componentFixture: ComponentFixture) => {
          const instance = componentFixture.debugElement.componentInstance;

          let controls = instance.taskAddForm.controls
          controls.owner.updateValue('new owner');
          controls.description.updateValue('new task');

          componentFixture.detectChanges();
          instance.onSubmit();

          const task = mockTasksService.getById('4');
          chai.expect(task.owner).to.equal('new owner');
          chai.expect(task.description).to.equal('new task');
        }
Example #28
0
 it('passes new clicker through to service', () => {
   let clickerName: string = 'dave';
   let input: any = clickerFormFixture.nativeElement.querySelectorAll('.text-input')[0];
   let button: any = clickerFormFixture.nativeElement.querySelectorAll('button')[0];
   spyOn(Utils, 'resetControl').and.callThrough();
   input.value = clickerName;
   clickerFormFixture.detectChanges();
   clickerForm['clickerNameInput']['updateValue'](clickerName, true);
   TestUtils.eventFire(input, 'input');
   TestUtils.eventFire(button, 'click');
   expect(clickerForm.newClicker).toHaveBeenCalledWith(Object({ clickerNameInput: clickerName }));
   expect(clickerForm['clickerService'].newClicker).toHaveBeenCalledWith(clickerName);
   expect(Utils.resetControl).toHaveBeenCalledWith(clickerForm['clickerNameInput']);
 });
        tsb.createAsync(TestComponent).then((fixture) => {
            testFixture = fixture;
            testFixture.detectChanges();

            childCompiled = testFixture.nativeElement;
            childCmp = testFixture.debugElement.children[0].componentInstance;

            expect(childCompiled).toBeDefined();
            expect(childCmp).toBeDefined();
            expect(childCompiled.querySelector('h6'))
                .toHaveText('From parent');
            expect(childCompiled.querySelector('h5'))
                .toHaveText('Hello test');
        });
    return tcb.createAsync(TestComponent).then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual('CREATE+2+test-cmp+{},CREATE+3+native-view+{},CREATE+4+router-outlet+{},ATTACH+1+2+0,ATTACH+2+3+0,ATTACH+3+4+0');
        mock.clearLogs();

        return new Promise((resolve: any) => {
          setTimeout(() => {
            rootRenderer.executeCommands();
            expect(mock.commandLogs.toString()).toEqual(
              'CREATE+5+cmp-a+{},CREATE+6+native-text+{},CREATE+7+native-rawtext+{"text":"a"},ATTACH+6+7+0,ATTACH+5+6+0,ATTACH+3+5+1');
            resolve();
          }, 0);
        });
      });