Git Product home page Git Product logo

karma-chai-plugins's Introduction

karma-chai-plugins

Chai browser plugins set for Karma

Dependency Status Greenkeeper badge Current version NPM downloads Travis Build Status AppVeyor Build Status

Installation

Install the karma-chai-plugins:

$ npm install karma-chai-plugins --save-dev

Add chai and plugins you need to the frameworks key in your Karma configuration:

module.exports = (config) ->
  config.set

    # frameworks to use
    frameworks: ['mocha', 'chai', 'chai-as-promised']

    # ...

Bundled plugins

Note: for using sinon, it is sufficient to add sinon-chai in karma frameworks. No need to add sinon.

Browser support

Same as Chai.js: IE 9+, Chrome 7+, FireFox 4+, Safari 5+ except should style that is currently not compatible with IE 9.

Consider karma-expect, if you need run tests in IE8 and lower.

Fair Warning

Currently, in order to use Chai-as-Promised when running tests within PhantomJS, a polyfill for Function.prototype.bind must be supplied. This plugin includes such a polyfill. If your code under test is intended to be run under PhantomJS in production, bear this in mind! You may need to supply your own polyfill in your project.

The Function.prototype.bind polyfill will be removed in the future v1.0 release of karma-chai-plugins.

chai-dom and chai-jquery can't work together, choose one of them.

Limited require.js support

karma-chai-plugins supports requirejs in tests, but for now it should be stated in frameworks before chai and other plugins:

module.exports = (config) ->
  config.set

    # frameworks to use
    frameworks: ['mocha', 'requirejs', 'chai', 'chai-as-promised']

    # ...

Contribution guidelines

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using npm test.

karma-chai-plugins's People

Contributors

duncanbeevers avatar garrinmf avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jewell-lgtm avatar kburson avatar kirill-konshin avatar maxmaximov avatar offirmo avatar ollym avatar princed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

karma-chai-plugins's Issues

Cannot use sinon-chai plugin

sinon-chai makes assertion easier. but currently, the chai object is not exposed, thus, users cannot call chai.use to load sinon-chai.

suggest to check if sinon-chai is available and load it automatically.

Several bugs related to sinon

  • In a webpack build
  • with package.json
"karma-chai-plugins": "^0.7.0",
  • with karma config plugins [... require('karma-chai-plugins') ...]
  • with karma config frameworks [... 'mocha', 'chai', 'sinon', 'sinon-chai']

Error: No provider for "framework:sinon"! (Resolving: framework:sinon)
at error (.../node_modules/di/lib/injector.js:22:12)

Let's add sinon ourselves : npm i --save-dev sinon

Error: No provider for "framework:sinon"! (Resolving: framework:sinon)
at error (.../node_modules/di/lib/injector.js:22:12)

Let's add karma-sinon ourselvess : npm i --save-dev karma-sinon + add it in karma config

TypeError: undefined is not an object

Wasn't karma-chai-plugins supposed to bundle all the things ?

expect( true ).to.be.ok() "object is not a function"

When I don't include "chai-as-promised" in my frameworks array in karma.conf.js from this repo the following test passes
it("passes", function(){ expect( true ).to.be.ok() });

When I do, I get TypeError: object is not a function, as it now only supports be.ok as a property rather than a method.

Is this an issue with chai-as-promised or with this repo?

expect is not defined

Is this a bug or a feature?

I'm using requirejs this way:

frameworks: ['mocha', 'mocha-debug', 'requirejs', 'chai', 'chai-as-promised', 'sinon-chai'],

loading chai with requirejs fails intermittently

I've been using this plugin for a while together with Karma 0.8 on a project that uses require.js. After upgrading to 0.10, it sometimes fails to load chai.js properly, causing the tests to fail. I can't reproduce the issue consistently, so it's hard to figure out why it fails.

Do you have any clue what might be causing the issue?

Can this load any Chai plugin, not just the bundled ones?

I'd like to use chai-date-string in my Karma/Mocha/Chai test setup, and I can't quit tell from the docs if karama-chai-plugin is meant to be used with any plugin, or just with the ones it comes bundled with.

It looks like that's the case, but despite following the docs, I still get the following error:

Error: No provider for "framework:chai-date-string"! (Resolving: framework:chai-date-string)

I've posted more details and file excerpts on Stack Overflow. Also note my follow up comment where I detail trying to use browserify as well for the plugin.

Broken sinon.js include.

It seems sinon reorganized some files in the latest release which breaks karma-chai-plugins

The error I´m seeing is

WARN [watcher]: Pattern "/home/gitlab_ci_runner/gitlab-ci-runner/tmp/builds/project-25/node_modules/karma-chai-plugins/node_modules/sinon/pkg/sinon.js" does not match any file.

And then a bunch of failures because sinon was not included properly :)

I´m not entirely sure but it could be related to this commit sinonjs/sinon@c2704b1 and the path specified here: https://github.com/princed/karma-chai-plugins/blob/master/index.js#L89

Plugin error when using Firefox with Travis

I got following error when using plugin with Travis. It works perfectly fine on my local machine. Karma conf setup:
https://github.com/gziolo/game-of-life/blob/76583c5621259a31a44f1e5ea3f31ed12199656d/karma.conf.js

I'm using karma-chai-plugins "~0.2.1" in my package.json

Running "karma:continuous" (karma) task
INFO [karma]: Karma v0.12.9 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [Firefox 19.0.0 (Linux)]: Connected on socket C7K4bYHupB63LoMeRq79 with id 65298600
Firefox 19.0.0 (Linux) ERROR: 'There is no timestamp for /absolute/home/travis/build/gziolo/game-of-life/node_modules/karma-chai-plugins/node_modules/chai/chai.js!'

Any idea what could go wrong? Temporary I fixed that using bower repo and requirejs setup. Anyway I would like to continue using plugin :)

Documentation incomplete

While trying to use the plugin, I noticed that simply adding the desired plugins to the frameworks array as stated in the README.md, e.g.

config.set({
  frameworks: ['mocha', 'chai', 'sinon-chai', 'chai-as-promised', 'chai-jquery'],
 // ...
});

does not work. I had to additionally add an entry to the plugins array, like so:

plugins: [
  'karma-phantomjs-launcher',
  'karma-mocha',
  'karma-chai-plugins',
  //'karma-chai',
  //'karma-sinon',
  'karma-mocha-reporter',
],
// ...

Maybe this should also be included in the docs, or was this possibly caused by something else?

busted w/ browserify

sinon doesn't end up in the global context when used with karma-browserify. I tried to hack around it, but no dice. Not sure what to do about this one... ended up ditching this package and just require-ing each chai, sinon and sinon-chai individually.

No timestamp error

Everytime I run my test I keep getting these errors (karma 0.10.4)

ERROR: 'There is no timestamp for /absolute/Users/ronald/ronald-angulartest/node_modules/karma-chai-plugins/node_modules/chai/chai.js!'
ERROR: 'There is no timestamp for /absolute/Users/ronald/ronald-angulartest/node_modules/karma-chai-plugins/node_modules/sinon-chai/lib/sinon-chai.js!'

karma installed globally while karma-chai-plugins installed locally. The tests seem to be running normally though..

Deprecation Warning with [email protected]

When installing with Node@16, this package triggers a deprecation warning:

npm WARN deprecated [email protected]: This package has been deprecated in favour of @sinonjs/samsam

I know, this package is not maintain, but would it be possible to upgrade the sinon dependency?

└─┬ [email protected]
  └─┬ [email protected]
    ├─┬ [email protected]
    │ └── [email protected] deduped
    └── [email protected]

No timestamp error

I'm getting the same issue as #4 ...

'There is no timestamp for /absolute/Users/.../node_modules/chai/chai.js!'
'There is no timestamp for /absolute/Users/.../node_modules/karma-chai-plugins/node_modules/sinon-chai/lib/sinon-chai.js!'
'There is no timestamp for /absolute/Users/.../node_modules/karma-chai-plugins/node_modules/chai-as-promised/lib/chai-as-promised.js!'

karma.conf.js

frameworks: ['mocha', 'requirejs', 'chai', 'sinon-chai', 'chai-as-promised'],

plugins: [
            'karma-mocha',
            'karma-chai-plugins',
            'karma-requirejs',
            'karma-coverage',
            'karma-mocha-reporter',
            'karma-chrome-launcher'
        ],

karma is global (0.12.31) and karma-chai-plugins is local. Tests seem to run ok.

If I change karma-chai-plugins/index.js to use relative paths, the error disappears.

Support chai 4.0

Looks like Chai has released a new 4.0 version. Any plans to update dependency to 4.x?

An in-range update of mocha is breaking the build 🚨

Version 3.5.3 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.5.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/appveyor/branch AppVeyor build succeeded Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v3.5.3

3.5.3 / 2017-09-11

🐛 Fixes

  • #3003: Fix invalid entities in xUnit reporter first appearing in v3.5.1 (@jkrems)
Commits

The new version differs by 3 commits.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Update sinon-chai to 2.9.0

The sinon-chai library has pushed an update to support sinon 2.1.0 as well. Can karma-chai-plugins be updated to match?

Function.prototype.bind polyfill is a gotcha

So there I was, happily working on my project (angular-debaser). After much blood, bile, and lymph, I got all my tests passing under PhantomJS and Chrome. The project makes liberal use of Function.prototype.bind.

Then John Q. Public comes along, installs angular-debaser into his project john-q-project, and tries to run his tests against PhantomJS (angular-debaser is a testing library, thus, is likely to be used in this context). His tests throw exceptions, pointing the finger at angular-debaser. Meanwhile, angular-debaser has green tests.

Looking through the history, it appears chai-as-promised needs a polyfill for browsers w/o support, namingly PhantomJS.

  1. karma-chai-plugins depends on chai-as-promised
  2. angular-debaser depends on karma-chai-plugins
  3. john-q-project depends on angular-debaser

Which of these packages should include the polyfill? Which shouldn't?

I released code that I thought worked. But really it only worked because the polyfill was present, I didn't realize that, and also didn't realize it was necessary for PhantomJS. This is my bad. However, I also know this wouldn't have happened had I installed chai-as-promised explicitly instead of karma-chai-plugins, as my tests would fail, I'd include my own polyfill, and I'd be smarter for it.

The author of chai-as-promised refuses to support PhantomJS. That's fine and good for him, because if he did, I'd be writing this issue in his project instead.

karma-chai-plugins should not include this polyfill, because ignorant authors (like me) of dependent projects (like angular-debaser) will ship broken code precisely because they used this bundle instead of the individual packages.

If you don't agree, can we agree to put a note in the README.md?

Epilogue: angular-debaser doesn't actually need a Function.prototype.bind polyfill; AngularJS provides its own bind() function that I decided to use instead. So, problem solved, but the pain and sorrow still lingers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.