Coder Social home page Coder Social logo

jamiemason / karma-jasmine-matchers Goto Github PK

View Code? Open in Web Editor NEW
46.0 3.0 7.0 36 KB

A Karma plugin to inject Jasmine-Matchers for Jasmine and Jest.

Home Page: https://www.npmjs.com/package/karma-jasmine-matchers

JavaScript 100.00%
jasmine javascript-tests jest karma testing

karma-jasmine-matchers's Introduction

karma-jasmine-matchers

A Karma plugin to inject Jasmine-Matchers for Jasmine and Jest.

NPM version NPM downloads Build Status Maintainability

Table of Contents

๐ŸŒฉ Installation

npm install karma-jasmine-matchers --save-dev

๐Ÿ“ API

See the following links for a full list of Matchers and Asymmetric Matchers provided.

๐Ÿ•น Usage

Just include 'jasmine-matchers' in the frameworks and 'karma-jasmine-matchers'in the plugins section of your config

module.exports = function(config) {
  config.set({
    frameworks: ["jasmine", "jasmine-matchers"],
    files: ["src/**/*.js", "src/**/*.spec.js"],
    // also you must add it as a plugin
    plugins: ["karma-jasmine", "karma-jasmine-matchers"]
  });
};

TypeScript and Angular CLI projects

If you are using TypeScript, you might want to npm install @types/jasmine-expect --save-dev in order to prevent your IDE from complaining about the new Matchers.

Also, if you run into TypeScript compilation errors when running your tests, add "jasmine-expect" to the "types" array in your tests' tsconfig file.

As an example, for an Angular CLI based project, this would be your tsconfig.spec.json file:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": ["jasmine", "node", "jasmine-expect"]
  },
  "files": ["test.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}

๐Ÿ™‹๐Ÿพโ€โ™€๏ธ Getting Help

Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.

๐Ÿ‘€ Other Projects

If you find my Open Source projects useful, please share them โค๏ธ

๐Ÿค“ Author

I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.

Follow JamieMason on GitHubย ย ย ย ย ย Follow fold_left on Twitter

karma-jasmine-matchers's People

Contributors

alecxe avatar davguij avatar jamiemason avatar msftenhanceprovenance avatar readme42 avatar robstoll 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

karma-jasmine-matchers's Issues

Add support for Jest.toMatchSnapshot

It would be great to have support for Jest.toMatchSnapshot matcher. This would allow test cases written in Jest to work as expected with Jest and also run the same test in a browser using Karma.

TypeError: expect(...).toHaveMethod is not a function

I've been trying to add jasmine-matchers to my Karma tests for a while now, and apparently it refuses to load.

I have the following config (with the irrelevant items left out):

        frameworks: [
            'requirejs',
            'jasmine',
            'jasmine-matchers'
        ],

        // list of files / patterns to load in the browser
        files: [
            // ...
            'src/test/javascript/test-main.js'
        ],

        browsers: [
            'PhantomJS'
        ],

        plugins: [
            'karma-jasmine',
            'karma-jasmine-matchers',
            'karma-requirejs',
            'karma-junit-reporter',
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-phantomjs-launcher'
        ]

The only thing I can think of that may collide is requirejs. The log shows that jasmine-matchers.js was indeed requested and loaded, also, looking at the browser running the karma tests, I can see jasmine-matchers.js in the resources tab.

Is it possible the karma-jasmine-matchers doesn't play nice with requirejs?

No provider for "framework:jasmine-matchers"

I have installed:

[email protected] node_modules/karma-jasmine-matchers
โ””โ”€โ”€ [email protected]

My karma config contains:

    frameworks: [
      'jasmine',
      'jasmine-matchers'
    ],
    plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-phantomjs-launcher', 'jasmine-matchers' ],

but when running tests, I still get:

Running "karma:continuous" (karma) task
WARN [plugin]: Cannot find plugin "jasmine-matchers".
  Did you forget to install it ?
  npm install jasmine-matchers --save-dev
Warning: No provider for "framework:jasmine-matchers"! (Resolving: framework:jasmine-matchers) Use --force to continue.

Aborted due to warnings.

For the latest version of Karma plugins key is not needed

here is my karma.conf.js

  config.set({
    frameworks: ["jasmine", "jasmine-matchers"],
    files: ["../index.js", "test.js"],
    reporters: ["progress"],
    port: 9876,  // karma web server port
    colors: true,
    logLevel: config.LOG_INFO,
    browsers: ["ChromeHeadless"],
    autoWatch: false,
    // singleRun: false, // Karma captures browsers, runs the tests and exits
    concurrency: Infinity,
  })

It works perfectly like that, but if I add the plugin key (as in the readme file), it starts complaining:

Cannot load browser "ChromeHeadless": it is not registered! Perhaps you are missing some plugin?

ReferenceError: Can't find variable: beforeEach when trying to run tests

I added to devDependencies in my package.json

        "jasmine-expect": "1.22.0",
        "karma-jasmine-matchers": "0.1.0"

Then I update my karma.conf.js with:

        frameworks: [
            'jasmine',
            'jasmine-matchers'
        ],

And then I do 'npm install'

And when I try to run the tests using grunt, I get the following error:

$ grunt test
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket cvjpmPbEi6vXxAlyM9pg with id 5324591
PhantomJS 1.9.7 (Windows 7) ERROR
  ReferenceError: Can't find variable: beforeEach
  at C:/XXXXX/web/node_modules/jasmine-expect/dist/jasmine-matchers.js:633


Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

If I remove jasmine-matchers from my framework lists, everything works fine again.

What I am doing wrong?

This is the full list of my devDependencies:

"devDependencies": {
        "grunt": "0.4.5",
        "grunt-concurrent": "0.5.0",
        "grunt-contrib-clean": "0.5.0",
        "grunt-contrib-jshint": "0.10.0",
        "grunt-contrib-less": "0.9.0",
        "grunt-contrib-watch": "0.6.1",
        "grunt-karma": "0.8.3",
        "grunt-ngdocs": "0.2.2",
        "jasmine-expect": "1.22.0",
        "jshint-stylish": "0.2.0",
        "karma": "0.12.16",
        "karma-chrome-launcher": "0.1.4",
        "karma-coverage": "0.2.2",
        "karma-firefox-launcher": "0.1.3",
        "karma-jasmine": "0.2.2",
        "karma-jasmine-matchers": "0.1.0",
        "karma-ng-html2js-preprocessor": "0.1.0",
        "karma-phantomjs-launcher": "0.1.4",
        "matchdep": "0.3.0",
        "phantomjs": "1.9.7-9"
    },

Support for jasmine-expect 2.x

Getting an error when trying to use toBeNonEmptyObject():

TypeError: 'undefined' is not a function (evaluating 'expect(Config).toBeNonEmptyObject()') at [...]

I installed with npm install karma-jasmine-matchers --save-dev and then I added 'jasmine-matchers' under frameworks: [...] in karma.conf.js.

Seems to be working because expect(Config).toBeObject() is successful. And when I comment-out 'jasmine-matchers' from the karma.conf.js file, expect(Config).toBeObject() then fails saying: TypeError: 'undefined' is not a function (evaluating 'expect(Config).toBeObject()'). So it seems that the jasmine-matchers plugin is working, but for some reason, it can't find the 'toBeNonEmptyObject()' function.

Any ideas what's going on?

console.log(Config) returns Object{cookies: Object{expires: 30, domain: 'localhost', path: '/'}}.

Installation instructions unclear

After running bower install jasmine-expect --save-dev and adding jasmine-matchers to my karma config file's frameworks array, it does not work.

I run grunt karma and I get the error:

Warning: No provider for "framework:jasmine-matchers"! (Resolving: framework:jasmine-matchers) Use --force to continue.

What installation step am I missing?

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.