You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that we'll have to deal with asynchronous behavior
async()
We can run test code within asynchronous zone
it('should show videos',async(()=>{fixture.detectChanges();// trigger data bindingfixture.whenStable().then(()=>{// wait for async getVideosfixture.detectChanges();// update view with videosexpect(getVideos()).toBe(testVideos);});}));
fakeAsync()
Or within fake asynchronous zone
it('should show videos',fakeAsync(()=>{fixture.detectChanges();// trigger data bindingtick();// wait for async getVideosfixture.detectChanges();// update view with videosexpect(getVideos()).toBe(testVideos);}));
Karma
Karma is a test runner with support e.g. for coverage reports and test results exports
Angular CLI comes with Karma installed
To run tests, type:
npm run test
E2E testing
End-to-End (E2E) tests test flow of the application
Ensures that the components of the application function together as expected
E2E tests often define use cases of the application
Protractor
E2E test framework for Angular applications
Runs tests against your application running in a real browser, interacting with it as a user would
Angular CLI comes with Protractor installed
To run E2E tests, type:
npm run e2e
Example spec
describe('Protractor Demo App',()=>{it('should have a title',()=>{browser.get('http://demo.com/protractor-demo/');expect(browser.getTitle()).toEqual('Demo Application');expect(element(by.css('h1')).toEqual('Header');});});