JS Testing Frameworks
Voici un recueil d'infos à propos des Frameworks de test ainsi que des assertion libraires populaire en 2018
Zero configuration testing platform. A l'origine, basé sur Jasmine (jusqu'à la v15, today v23)
Strengths of Jest
- The biggest advantage of using Jest is that it works out of the box with minimal setup or configuration. Much of this is because it comes with an assertion library and mocking support. It's built into the popular create-react-app
- Jest also supports snapshot testing, which can be really handy for preventing accidental UI regressions. Snapshots render a UI component, take a screenshot of it, and compare the component to a reference image stored with the test: expect(component).toMatchSnapshot();
- Jest runs your tests concurrently in parallel (asynchronous testing), providing a smoother, faster test run
- running on Node.js and in the browser
- configuration can be defined in the package.json file of your project, or through a jest.config.js file or through the --config <path/to/js|json>
Weaknesses of Jest
Mocha provides developers with a base test framework, allowing you to have options as to which assertion, mocking, and spy libraries you want to use.
Strengths of Mocha
- Community due to it's lifetime.
Weaknesses of Mocha
Mocha’s main weakness is that it requires more configuration.
Sinon is a popular mocking and spy library. With robust documentation on fakes, stubs, spies, and mocks, Sinon is easy to pick up and integrate with Mocha.
Enzyme was developed by Airbnb for testing React components’ outputs. Enzyme shallow renders your components so that you ensure that your component is being passed the correct props and behaviors. Enzyme can be used in addition to any testing framework. Enzyme is easy to configure and has additional libraries for integration with popular libraries (like
chai-enzyme).With Enzyme we can create a mock DOM to test whether components are rendered correctly, and whether they behave correctly when acted upon.Enzyme’s mock rendering can either be done through shallow rendering or full DOM rendering. Enzyme v3 support React 16; Enzyme is unopinionated regarding which test runner or assertion library you use, and should be compatible with all major test runners and assertion libraries out there.
Nightmare for integration testing
Headless alternatives à PhantomJs qui est ☠️
Puppeteer is a Node.js library, developed by Google. It provides a convenient Node.js API to control Headless Chrome that is just a regular Chrome v59+ that is launched with the --headless flag that exposes an API to control it
BrowserSync affiche en parallèle le résultat de nos dev sur plusieurs écrans (avec live reloading): From live reloads to URL pushing, form replication to click mirroring, Browsersync cuts out repetitive manual tasks
medium Jest vs Mocha 2018
Stats d'adoption des framework et + (2016 et 2017)
Compilation de toutes les infos nécessaire pour comprendre les différents outils intervenant dans les tests en JS:
- Provide a testing structure (Mocha, Jasmine, Jest, Cucumber)
- Provide assertions functions (Chai, Jasmine, Jest, Unexpected)
- Generate, display, and watch test results (Mocha, Jasmine, Jest, Karma)
- Generate and compare snapshots of component and data structures to make sure changes from previous runs are intended (Jest, Ava)
- Provide mocks, spies, and stubs (Sinon, Jasmine, enzyme, Jest, testdouble)
- Generate code coverage reports (Istanbul, Jest, Blanket). Istanbul is built into Jest, so configuration is handled directly by Jest. The report can be generated by triggering jest with the
--coverageflag. Jest provides documentation for configuring test coverage here.
- Provide a browser or browser-like environment with a control on their scenarios execution (Protractor, Nightwatch, Phantom, Casper)