E2E testing and other tools

As with unit testing, there are also many popular options for writing end-to-end tests:

  • Protractor (https://www.protractortest.org) is an end-to-end test framework created for Angular applications. Protractor tests are executed in a real web browser, interacting with it just like a user would (that is, clicking on buttons, waiting for elements to appear, and so on). Protractor (like many other E2E testing solutions) uses Selenium WebDriver (https://www.seleniumhq.org/projects/webdriver) to interact with the browser.
  • Cypress (https://www.cypress.io) is another popular open source E2E testing solution.
  • Istanbul (https://istanbul.js.org) is a tool that you can use to generate test coverage reports, allowing you to verify that you test your code base properly.
  • Puppeteer: (https://github.com/GoogleChrome/puppeteer) is a tool that allows you to easily interact with the Google Chrome (or Chromium) web browser through a high-level API. It runs in headless mode by default (that is, it does not open a browser window). Puppeteer can be used in the context of E2E tests (for example, to make screenshots during tests, export pages as PDFs, and so on).

Testing libraries use matchers to define assertions in tests. Here's a basic example using Jest:

test('the sum of 1 and 2 is 3', () => { 
  expect(1 + 2).toBe(3); 
}); 

In the preceding test, we've used the expect function to define our expectation and the toBe matcher to define the expected result. Different libraries provide different matchers, but the ideas are similar. Here are some of the matchers provided by Jest:

  • toBeNull
  • toBeDefined
  • toBeTruthy
  • not
  • toBeLessThan
  • toMatch

Usually, matchers can be combined. Here's an example: expect(value).not.toMatch(/foo/). You can find the full list of matchers included with Jest at https://jestjs.io/docs/en/expect.

And there are even more available, thanks to the Jest community effort: https://github.com/jest-community/jest-extended.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.161.77