All Projects β†’ dzikowski β†’ angularjs-jest

dzikowski / angularjs-jest

Licence: MIT license
Testing AngularJS applications with Jest

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to angularjs-jest

snappify
A generator of Jest snapshot-based tests for React components written with TypeScript πŸ“Έ
Stars: ✭ 64 (+166.67%)
Mutual labels:  jest, jest-snapshots
jest-playground
Playing around with Jest - Subscribe to my YouTube channel: https://bit.ly/CognitiveSurge
Stars: ✭ 24 (+0%)
Mutual labels:  jest, jest-snapshots
Jest Image Snapshot
✨ Jest matcher for image comparisons. Most commonly used for visual regression testing.
Stars: ✭ 2,940 (+12150%)
Mutual labels:  jest, jest-snapshots
jest-extended-snapshot
Additional Jest matchers for snapshot testing.
Stars: ✭ 18 (-25%)
Mutual labels:  jest, jest-snapshots
testing-reactjs-examples
πŸ§ͺ "What should we test in our React components" - presentation examples.
Stars: ✭ 23 (-4.17%)
Mutual labels:  jest, jest-snapshots
nuxt-boilerplate
Nuxt.js Boilerplate
Stars: ✭ 25 (+4.17%)
Mutual labels:  jest, jest-snapshots
Codecharta
CodeCharta visualizes multiple code metrics using 3D tree maps.
Stars: ✭ 85 (+254.17%)
Mutual labels:  angularjs, jest
patent-free-react-ecosystem-migration-plan
Patent Free React Ecosystem Migration Plan
Stars: ✭ 15 (-37.5%)
Mutual labels:  jest
nodejs-vuejs-mysql-boilerplate
Node.js (REST API) + Vue.js/Nuxt.js (Frontend/Backend) + MySQL Boilerplate
Stars: ✭ 134 (+458.33%)
Mutual labels:  jest
ng-webcam
ngWebcam is an AngularJS directive for capturing images from your computer's camera, and delivering then to you as data uri.
Stars: ✭ 14 (-41.67%)
Mutual labels:  angularjs
symfony-angular-todomvc
An implementation of TodoMVC using AngularJS and Symfony REST Edition
Stars: ✭ 94 (+291.67%)
Mutual labels:  angularjs
xv
❌ βœ”οΈ zero-config test runner for simple projects
Stars: ✭ 588 (+2350%)
Mutual labels:  jest
ts-nextjs-tailwind-starter
πŸ”‹ Next.js + Tailwind CSS + TypeScript starter packed with useful development features
Stars: ✭ 880 (+3566.67%)
Mutual labels:  jest
react-jest-enzyme-example
A minimal configuration for testing React components with Jest and Enzyme.
Stars: ✭ 23 (-4.17%)
Mutual labels:  jest
ionic2-jest-example
Example of how to test an Ionic2 app with Jest
Stars: ✭ 43 (+79.17%)
Mutual labels:  jest
ng-highcharts
Angular Directive for Highcharts
Stars: ✭ 12 (-50%)
Mutual labels:  angularjs
sentry
πŸ‘ A self hosted dashboard to monitor servers and services.
Stars: ✭ 19 (-20.83%)
Mutual labels:  jest
schema.tl
πŸ“œ Easy-to-use TL-Schema viewer
Stars: ✭ 55 (+129.17%)
Mutual labels:  angularjs
manager
OVHcloud Control Panel
Stars: ✭ 153 (+537.5%)
Mutual labels:  angularjs
typescript-nuxtjs-boilerplate
🍱 Nuxt.js with TypeScript and Run with docker and docker-compose πŸΆπŸ¦„πŸ”₯ visit: https://typescript-nuxtjs-boilerplate.netlify.com/example
Stars: ✭ 51 (+112.5%)
Mutual labels:  jest

angularjs-jest

Build Status Version Downloads

Testing AngularJS applications with Jest. You can see the article on Medium for more information: AngularJS and Jest. Three steps to improve your legacy frontend tests.

Instalation

npm install angularjs-jest --save-dev or yarn add --dev angularjs-jest

Required libraries in your project:

  • angular in version 1.5.0 or higher
  • angular-mocks in version 1.5.0 or higher
  • jest in version higher than 23.0.1

Usage

Test app setup

import { createTestApp } from 'angularjs-jest';

const testApp = createTestApp({

  // modules to include in test app (optional)
  modules: ['some.test.module'],
  
  // services or service components to mock in test app (optional)
  mocks: {
    SomeSyncService: { get: () => 42 },
    SomeAsyncService: { getAsync: () => Promise.resolve('42, I promise') },
  },
  
  // additional services or service components you want to access (optional)
  access: ['$http']
});

Testing the view

testApp.$scope.name = 'Alice';

const element = testApp.render('Hello {{ name }}');

expected(element.text()).toEqual('Hello Alice')

The render function accepts any valid AngularJS template. For example you can use an arbitrary HTML code or the components you have defined in your application (you just need to remember to provide module names in the modules parameter of createTestApp).

Asynchronous tests

Let's assume you have the following component defined in your app:

module.component('asyncComponent', {
  template: '<strong>Answer:</strong> {{ $ctrl.answer }}',
  controller(SomeAsyncService) {
    this.$onInit = () => SomeAsyncService.getAsync().then((resp) => { this.answer = resp; });
  }
})

You can test this component the following way:

const element = testApp.render('<async-component></async-component>');

// at first it contains no answer
expect(element.text().trim()).toEqual('Answer:');

// but then the promise resolves and the answer appears
await testApp.eventually(() => expect(element.text().trim()).toEqual('Answer: 42, I promise'));

The eventually function returns a Promise. This Promise is resolved if the provided function eventually passes, and it is rejected if the function fails to pass after several calls.

By default there is no delay between the calls, however it can be configured, which is useful when some services respond with delay. In the example below the assertion will be performed at most 10 times with 200 ms delay between the calls.

await testApp.eventually(
  () => expect(element.text().trim()).toEqual('Answer: 42, I promise'),
  { interval: 200, limit: 10 },
);

Snapshot tests

The library provides a snapshot serializer for HTML code generated by AngularJS. It removes some of the clutter comments generated by AngularJS and reformats the HTML to be developer-friendly. It works out of the box:

const element = testApp.render('Hello {{ name }}');
expect(element).toMatchSnapshot();

In case of an asynchronous component, when the state stabilizes after a few digest cycles, you should make an additional assertion to check if the component is ready. For example:

const element = testApp.render('<async-component></async-component>');

await testApp.eventually(() => expect(element.text()).toContain('42, I promise'));

expect(element).toMatchSnapshot();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].