Debugging and Testing

Note for full Intellij debug compatabillity you must use Google Chrome. It's also sort of a hassle to configure linux for tests the first time; ensure CHROME_BIN env variable is set to chromium, or add a firefox config to Karma.js

Debugging (In Intellij)

Go to 'Edit Configurations...', then find JavaScript Debgger, there is a default Angular config

Testing

// Set up testing eviornment
fdescribe('DataService', () => {
  let service: DataService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(DataService);
  });

  // tests begin with it
  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  // focused test
  fit('addBook increases size of books', () => {
    const book = new Book();
    const before = service.books.length;
    service.addBook(book);
    expect(service.books.length).toBeGreaterThan(before);
  });
});

Angular Environments

Angular environment variables are store in a folder under src/ called environments in files environment.ts and environment.prod.ts for testing and production. It contains key value pairs. We can import the environment for access to all these variables.

NEVER import environment.prod.ts. Import environment.ts

To run Angular with production enviornment: ng serve --prod which is a shortcut for ng serve -c production (Although in actual deployment we would not use the Angular server) Angular.json tells the app where to get production and regular environment variables, and can even replace files when certian environments are activated It's a good idea to have at least 3 enviornments; One for Production, for development or localhost, and a local version that has data stored internally.


Revision #1
Created 16 April 2022 23:26:26 by Elkip
Updated 16 April 2022 23:40:55 by Elkip