<commit_before>/**
 * @license
 * Copyright Google Inc. All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */

import {Component, Injectable, Input} from '@angular/core';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBed, async, withModule} from '@angular/core/testing';
import {dispatchEvent} from '@angular/platform-browser/testing/browser_util';
import {expect} from '@angular/platform-browser/testing/matchers';

@Component({selector: 'simple-comp', template: `<span>Original {{simpleBinding}}</span>`})
@Injectable()
class SimpleComp {
  simpleBinding: string;
  constructor() { this.simpleBinding = 'Simple'; }
}

@Component({
  selector: 'my-if-comp',
  template: `MyIf(<span *ngIf="showMore">More</span>)`,
})
@Injectable()
class MyIfComp {
  showMore: boolean = false;
}

@Component({selector: 'autodetect-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AutoDetectComp {
  text: string = '1';

  click() { this.text += '1'; }
}

@Component({selector: 'async-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AsyncComp {
  text: string = '1';

  click() {
    Promise.resolve(null).then((_) => { this.text += '1'; });
  }
}

@Component({selector: 'async-child-comp', template: '<span>{{localText}}</span>'})
class AsyncChildComp {
  localText: string = '';

  @Input()
  set text(value: string) {
    Promise.resolve(null).then((_) => { this.localText = value; });
  }
}

@Component({
  selector: 'async-change-comp',
  template: `<async-child-comp (click)='click()' [text]="text"></async-child-comp>`
})
class AsyncChangeComp {
  text: string = '1';

  click() { this.text += '1'; }
}

@Component({selector: 'async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AsyncTimeoutComp {
  text: string = '1';

  click() {
    setTimeout(() => { this.text += '1'; }, 10);
  }
}

@Component(
    {selector: 'nested-async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`})
class NestedAsyncTimeoutComp {
  text: string = '1';

  click() {
    setTimeout(() => { setTimeout(() => { this.text += '1'; }, 10); }, 10);
  }
}

export function main() {
  describe('ComponentFixture', () => {
    beforeEach(async(() => {
      TestBed.configureTestingModule({
        declarations: [
          AutoDetectComp, AsyncComp, AsyncTimeoutComp, NestedAsyncTimeoutComp, AsyncChangeComp,
          MyIfComp, SimpleComp, AsyncChildComp
        ]
      });
    }));

    it('should auto detect changes if autoDetectChanges is called', () => {

      let componentFixture = TestBed.createComponent(AutoDetectComp);
      expect(componentFixture.ngZone).not.toBeNull();
      componentFixture.autoDetectChanges();
      expect(componentFixture.nativeElement).toHaveText('1');

      let element = componentFixture.debugElement.children[0];
      dispatchEvent(element.nativeElement, 'click');

      expect(componentFixture.isStable()).toBe(true);
      expect(componentFixture.nativeElement).toHaveText('11');
    });

    it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
       withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {

         let componentFixture = TestBed.createComponent(AutoDetectComp);
         expect(componentFixture.nativeElement).toHaveText('1');

         let element = componentFixture.debugElement.children[0];
         dispatchEvent(element.nativeElement, 'click');

         expect(componentFixture.nativeElement).toHaveText('11');
       }));

    fit('should signal through whenStable when the fixture is stable (autoDetectChanges)',
        async(() => {
          let componentFixture = TestBed.createComponent(AsyncComp);
          componentFixture.autoDetectChanges();
          expect(componentFixture.nativeElement).toHaveText('1');

          let element = componentFixture.debugElement.children[0];
          dispatchEvent(element.nativeElement, 'click');
          expect(componentFixture.nativeElement).toHaveText('1');

          // Component is updated asynchronously. Wait for the fixture to become stable
          // before checking for new value.
          expect(componentFixture.isStable()).toBe(false);
          componentFixture.whenStable().then((waited) => {
            expect(waited).toBe(true);
            expect(componentFixture.nativeElement).toHaveText('11');
          });
        }));

    it('should signal through isStable when the fixture is stable (no autoDetectChanges)',
       async(() => {
         let componentFixture = TestBed.createComponent(AsyncComp);

         componentFixture.detectChanges();
         expect(componentFixture.nativeElement).toHaveText('1');<commit_msg>fix(tests): remove fit in component_fixture_spec (#10961)<commit_after>/**
 * @license
 * Copyright Google Inc. All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */

import {Component, Injectable, Input} from '@angular/core';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBed, async, withModule} from '@angular/core/testing';
import {dispatchEvent} from '@angular/platform-browser/testing/browser_util';
import {expect} from '@angular/platform-browser/testing/matchers';

@Component({selector: 'simple-comp', template: `<span>Original {{simpleBinding}}</span>`})
@Injectable()
class SimpleComp {
  simpleBinding: string;
  constructor() { this.simpleBinding = 'Simple'; }
}

@Component({
  selector: 'my-if-comp',
  template: `MyIf(<span *ngIf="showMore">More</span>)`,
})
@Injectable()
class MyIfComp {
  showMore: boolean = false;
}

@Component({selector: 'autodetect-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AutoDetectComp {
  text: string = '1';

  click() { this.text += '1'; }
}

@Component({selector: 'async-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AsyncComp {
  text: string = '1';

  click() {
    Promise.resolve(null).then((_) => { this.text += '1'; });
  }
}

@Component({selector: 'async-child-comp', template: '<span>{{localText}}</span>'})
class AsyncChildComp {
  localText: string = '';

  @Input()
  set text(value: string) {
    Promise.resolve(null).then((_) => { this.localText = value; });
  }
}

@Component({
  selector: 'async-change-comp',
  template: `<async-child-comp (click)='click()' [text]="text"></async-child-comp>`
})
class AsyncChangeComp {
  text: string = '1';

  click() { this.text += '1'; }
}

@Component({selector: 'async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`})
class AsyncTimeoutComp {
  text: string = '1';

  click() {
    setTimeout(() => { this.text += '1'; }, 10);
  }
}

@Component(
    {selector: 'nested-async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`})
class NestedAsyncTimeoutComp {
  text: string = '1';

  click() {
    setTimeout(() => { setTimeout(() => { this.text += '1'; }, 10); }, 10);
  }
}

export function main() {
  describe('ComponentFixture', () => {
    beforeEach(async(() => {
      TestBed.configureTestingModule({
        declarations: [
          AutoDetectComp, AsyncComp, AsyncTimeoutComp, NestedAsyncTimeoutComp, AsyncChangeComp,
          MyIfComp, SimpleComp, AsyncChildComp
        ]
      });
    }));

    it('should auto detect changes if autoDetectChanges is called', () => {

      let componentFixture = TestBed.createComponent(AutoDetectComp);
      expect(componentFixture.ngZone).not.toBeNull();
      componentFixture.autoDetectChanges();
      expect(componentFixture.nativeElement).toHaveText('1');

      let element = componentFixture.debugElement.children[0];
      dispatchEvent(element.nativeElement, 'click');

      expect(componentFixture.isStable()).toBe(true);
      expect(componentFixture.nativeElement).toHaveText('11');
    });

    it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
       withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {

         let componentFixture = TestBed.createComponent(AutoDetectComp);
         expect(componentFixture.nativeElement).toHaveText('1');

         let element = componentFixture.debugElement.children[0];
         dispatchEvent(element.nativeElement, 'click');

         expect(componentFixture.nativeElement).toHaveText('11');
       }));

    it('should signal through whenStable when the fixture is stable (autoDetectChanges)',
        async(() => {
          let componentFixture = TestBed.createComponent(AsyncComp);
          componentFixture.autoDetectChanges();
          expect(componentFixture.nativeElement).toHaveText('1');

          let element = componentFixture.debugElement.children[0];
          dispatchEvent(element.nativeElement, 'click');
          expect(componentFixture.nativeElement).toHaveText('1');

          // Component is updated asynchronously. Wait for the fixture to become stable
          // before checking for new value.
          expect(componentFixture.isStable()).toBe(false);
          componentFixture.whenStable().then((waited) => {
            expect(waited).toBe(true);
            expect(componentFixture.nativeElement).toHaveText('11');
          });
        }));

    it('should signal through isStable when the fixture is stable (no autoDetectChanges)',
       async(() => {
         let componentFixture = TestBed.createComponent(AsyncComp);

         componentFixture.detectChanges();
         expect(componentFixture.nativeElement).toHaveText('1');
{'fraction_non_alphanumeric': 0.15975168132436626, 'fraction_numerical': 0.006725297465080186, 'mean_word_length': 3.9876160990712073, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2975600', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2747, 'n_words': 576}