https://github.com/pvdlg/karma-jasmine-jquery
A Karma plugin for jasmine-jquery
https://github.com/pvdlg/karma-jasmine-jquery
jasmine jasmine-jquery jquery karma karma-framework karma-jasmine karma-plugin
Last synced: 24 days ago
JSON representation
A Karma plugin for jasmine-jquery
- Host: GitHub
- URL: https://github.com/pvdlg/karma-jasmine-jquery
- Owner: pvdlg
- License: mit
- Created: 2017-07-13T20:42:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-27T05:15:12.000Z (about 5 years ago)
- Last Synced: 2025-04-09T17:01:39.197Z (26 days ago)
- Topics: jasmine, jasmine-jquery, jquery, karma, karma-framework, karma-jasmine, karma-plugin
- Language: JavaScript
- Size: 181 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# **karma-jasmine-jquery**
A Karma plugin for [Jasmine-jQuery](https://github.com/velesin/jasmine-jquery).
[](https://travis-ci.org/pvdlg/karma-jasmine-jquery)
[](https://ci.appveyor.com/project/pvdlg/karma-jasmine-jquery)
[](https://codecov.io/gh/pvdlg/karma-jasmine-jquery)
[](https://greenkeeper.io/)
[](https://github.com/pvdlg/karma-jasmine-jquery/blob/master/LICENSE)## Installation
```bash
npm install karma jasmine-core karma-jasmine jasmine-jquery @metahub/karma-jasmine-jquery --save-dev
```
**Note: `@metahub/karma-jasmine-jquery` depends on [Jasmine](https://github.com/jasmine/jasmine), [Karma-Jasmine](https://github.com/karma-runner/karma-jasmine), and [Jasmine-jQuery](https://github.com/velesin/jasmine-jquery) but they are not bundled, just defined as [peer-dependencies](https://nodejs.org/en/blog/npm/peer-dependencies). This allow you to use any version independently of `@metahub/karma-jasmine-jquery`.**## Configuration
### Standard
```js
module.exports = function(config) {
config.set({
plugins: ['@metahub/karma-jasmine-jquery', 'karma-*'],
frameworks: ['jasmine-jquery'],
});
};
```
**Note: Karma can auto-load plugins named `karma-*` (see [plugins](http://karma-runner.github.io/1.0/config/plugins.html)). Unfortunatly it doesn't work with [scoped packages](https://docs.npmjs.com/misc/scope), therefore `@metahub/karma-jasmine-jquery` has to be explicitly added to the `plugins` configuration. In order to continue to automatically load other plugins you can add `karma-*` to the `plugins` configuration.****Note: `@metahub/karma-jasmine-jquery` will automatically import the necesary files from [jQuery](https://github.com/jquery/jquery), [Jasmine](https://github.com/jasmine/jasmine) and [Karma-Jasmine](https://github.com/karma-runner/karma-jasmine). No need to add them to `plugins` or `frameworks`.**
In your [Jasmine](https://github.com/jasmine/jasmine) tests, [jQuery](https://github.com/jquery/jquery) will be accessible with `$` or `jQuery`:
```js
describe('Jasmine tests with Jasmine-jQuery', () => {
it('shoud allow to use jQuery', () => {
setFixtures('fixture content');
expect($('#fixture')).toHaveText('fixture content');
expect(jQuery('#fixture')).toHaveClass('fixture-class');
});
});
```### With a custom jQuery version
`@metahub/karma-jasmine-jquery` uses a recent version of [jQuery](https://github.com/jquery/jquery) but it might be desirable to use the specific version of [jQuery](https://github.com/jquery/jquery) used in your application for executing the [Jasmine](https://github.com/jasmine/jasmine) tests.In that case you can use [Karma-jQuery](https://github.com/scf2k/karma-jquery):
```bash
npm install karma-jquery --save-dev
``````js
module.exports = function(config) {
config.set({
plugins: ['@metahub/karma-jasmine-jquery', 'karma-*'],
frameworks: ['jasmine-jquery', 'jquery-1.8.3'],
});
};
```In your [Jasmine](https://github.com/jasmine/jasmine) tests, the version of [jQuery](https://github.com/jquery/jquery) configured with [Karma-jQuery](https://github.com/scf2k/karma-jquery) will be accessible with `$` or `jQuery`. The version of [jQuery](https://github.com/jquery/jquery) used by `@metahub/karma-jasmine-jquery` will be accessible with `$j` or `jasmineJQuery`:
```js
describe('Jasmine tests with Jasmine-jQuery and Karma-jQuery', () => {
it('shoud allow to use a specific version jQuery', () => {
expect($.fn.jquery).toBe('1.8.3');
$.fn.jquery // 1.8.3 => version installed by Karma-jQuery
jQuery.fn.jquery // 1.8.3 => version installed by Karma-jQueryexpect($j.fn.jquery).toBe('3.2.1');
$j.fn.jquery // 3.2.1 => version installed by @metahub/karma-jasmine-jquery
jasmineJQuery.fn.jquery // 3.2.1 => version installed by @metahub/karma-jasmine-jquery
});
});
```