How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import { TestBed } from '@angular/core/testing';
    import { provideMockStore, MockStore } from '@ngrx/store/testing';
    import { cold } from 'jasmine-marbles';
     
    import { AuthGuard } from '../guards/auth.guard';
     
    describe('Auth Guard', () => {
      let guard: AuthGuard;
      let store: MockStore;
      const initialState = { loggedIn: false };
     
      beforeEach(() => {
        TestBed.configureTestingModule({
          imports: [
            // any modules needed
          ],
          providers: [
            AuthGuard,
            provideMockStore({ initialState }),
            // other providers
          ],
        });
     
        store = TestBed.inject(MockStore);
        guard = TestBed.inject(AuthGuard);
      });
     
      it('should return false if the user state is not logged in', () => {
        const expected = cold('(a|)', { a: false });
     
        expect(guard.canActivate()).toBeObservable(expected);
      });
     
      it('should return true if the user state is logged in', () => {
        store.setState({ loggedIn: true });
     
        const expected = cold('(a|)', { a: true });
     
        expect(guard.canActivate()).toBeObservable(expected);
      });
    });
    Docs
  • import { fakeAsync, TestBed, tick } from '@angular/core/testing';
    
    import { CanvasComponent } from './canvas.component';
    
    describe('CanvasComponent', () => {
      beforeEach(async () => {
        await TestBed
            .configureTestingModule({
              declarations: [CanvasComponent],
            })
            .compileComponents();
      });
    
      it('should be able to generate blob data from canvas', fakeAsync(() => {
           const fixture = TestBed.createComponent(CanvasComponent);
           const canvasComp = fixture.componentInstance;
    
           fixture.detectChanges();
           expect(canvasComp.blobSize).toBe(0);
    
           tick();
           expect(canvasComp.blobSize).toBeGreaterThan(0);
         }));
    });
    Docs
  • import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
    
    import { BannerComponent } from './banner.component';
    
    describe('BannerComponent', () => {
      let component: BannerComponent;
      let fixture: ComponentFixture<BannerComponent>;
    
      beforeEach(waitForAsync(() => {
        TestBed.configureTestingModule({declarations: [BannerComponent]}).compileComponents();
      }));
    
      beforeEach(() => {
        fixture = TestBed.createComponent(BannerComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
      });
    
      it('should create', () => {
        expect(component).toBeDefined();
      });
    });
    Docs
  • beforeEach(() => {
      TestBed.configureTestingModule({
        // provide the component-under-test and dependent service
        providers: [
          WelcomeComponent,
          { provide: UserService, useClass: MockUserService }
        ]
      });
      // inject both the component and the dependent service.
      comp = TestBed.inject(WelcomeComponent);
      userService = TestBed.inject(UserService);
    });
    Docs
  • describe('HttpClient testing', () => {
      let httpClient: HttpClient;
      let httpTestingController: HttpTestingController;
    
      beforeEach(() => {
        TestBed.configureTestingModule({
          imports: [ HttpClientTestingModule ]
        });
    
        // Inject the http service and test controller for each test
        httpClient = TestBed.inject(HttpClient);
        httpTestingController = TestBed.inject(HttpTestingController);
      });
      /// Tests begin ///
    });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples