Skip to content

Instantly share code, notes, and snippets.

@goelinsights
Last active April 10, 2020 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goelinsights/770922e3903186ea39f0ae40b9516ee8 to your computer and use it in GitHub Desktop.
Save goelinsights/770922e3903186ea39f0ae40b9516ee8 to your computer and use it in GitHub Desktop.
Jest examples in angular

Services

example.service.spec.ts

describe('ExampleService', () => { 
  const _httpClient = new HttpClient(null); 
  const _otherService = new OtherService(null, null);

  let service: ExampleService; 
  beforeEach(() => { 
    service = new TimingBenchmarkService(_httpClient, _otherService); 
  }); 
  test('the service multiplies two numbers', () => { 
    expect(service.multiply(1, 2)).toEqual(2); 
  }); 
  test('service.produceWidgets', () => { 
    expect(service.produceWidgets(1, 60)).toEqual('60 widgets produced in 1 hour'); 
  }); 
});

Unit Tests (shallow, no Test Bed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment