UNPKG

3.06 kBMarkdownView Raw
1# karma-jasmine
2
3[![npm version](https://img.shields.io/npm/v/karma-jasmine?style=flat-square)](https://www.npmjs.com/package/karma-jasmine)
4[![npm downloads](https://img.shields.io/npm/dm/karma-jasmine?style=flat-square)](https://www.npmjs.com/package/karma-jasmine)
5[![Release Workflow Status](https://img.shields.io/github/workflow/status/karma-runner/karma-jasmine/Release/master?style=flat-square&logo=github&label=Release)](https://github.com/karma-runner/karma-jasmine/actions/workflows/release.yml?query=branch%3Amaster)
6[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen?style=flat-square)](https://github.com/karma-runner/karma-jasmine)
7[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079?style=flat-square)](https://github.com/semantic-release/semantic-release)
8
9> Adapter for the [Jasmine](https://jasmine.github.io/) testing framework.
10
11## Installation
12
13```bash
14npm install karma-jasmine --save-dev
15```
16
17## Configuration
18
19```js
20// karma.conf.js
21module.exports = function(config) {
22 config.set({
23 frameworks: ['jasmine'],
24 files: [
25 '*.js'
26 ]
27 })
28}
29```
30
31If you want to run only some tests whose name match a given pattern you can do this in the following way
32
33```bash
34$ karma start &
35$ karma run -- --grep=<pattern>
36```
37
38where pattern is either a string (e.g `--grep=#slow` runs tests containing "#slow") or a Regex (e.g `--grep=/^(?!.*#slow).*$/` runs tests _not_ containing "#slow").
39
40You can also pass it to `karma.config.js`:
41
42```js
43module.exports = function(config) {
44 config.set({
45 // ...
46 client: {
47 args: ['--grep', '<pattern>'],
48 // ...
49 }
50 })
51}
52```
53
54If you want to pass configuration options directly to jasmine you can do this in the following way
55
56```js
57module.exports = function(config) {
58 config.set({
59 client: {
60 jasmine: {
61 random: true,
62 seed: '4321',
63 oneFailurePerSpec: true,
64 failFast: true,
65 timeoutInterval: 1000
66 }
67 }
68 })
69}
70```
71
72## Debug by URL
73
74Failing tests print a debug URL with `?spec=`. Use it with `--no_single_run`
75and paste it into your browser to focus on a single failing test.
76
77## Sharding
78
79By setting `config.client.shardIndex` and `config.client.totalShards`, you can
80run a subset of the full set of specs. Complete sharding support needs to be
81done in the process that calls karma, and would need to support test result
82integration across shards.
83
84## Custom spec filter
85
86Providing a [custom spec filter](https://jasmine.github.io/api/edge/Configuration#specFilter) is also supported.
87
88Example:
89
90```js
91// Users are able to set a custom specFilter themselves
92
93jasmine.getEnv().configure({
94 specFilter: function (spec) {
95 return spec.getFullName() === 'spec that succeeds'
96 }
97})
98
99describe('spec', () => {
100 it('that fails', () => {
101 fail('This spec should not run!')
102 })
103
104 it('that succeeds', () => {
105 expect(1).toBe(1)
106 })
107})
108```
109
110---
111
112For more information on Karma see the [homepage](https://karma-runner.github.io/).