jasmine-matcher-wrapper
Wraps Jasmine 1.x matchers for use with Jasmine 2
Last updated 4 years ago by searls .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jasmine-matcher-wrapper 
SYNC missed versions from official npm registry.

jasmine-matcher-wrapper

This is a Jasmine 2.0 helper for users who want to use legacy Jasmine 1.x matchers under Jasmine 2.0.

This may be particularly useful to anyone who publishes Jasmine support libraries and wants to maintain support of both Jasmine 1.x and 2.x simultaneously.

Download the latest release here

Usage

Usage is really easy.

Say that you have some jasmine 1.x matchers in an object:

var jasmine1Matchers = {
  toBeNamed: function(name) {
    var color = this.actual;
    this.message = function() {
      return "expected foo to be " + name + " but was " + color.name;
    };
    return color.name === name;
  }
};

And you want to use them in jasmine 2.x, which provides a jasmine.addMatchers function (absent from jasmine 1.x). After loading jasmine-matcher-wrapper you can:

jasmine.addMatchers(jasmine.matcherWrapper.wrap(jasmine1Matchers));

And now a failing spec like this:

expect(name: "yellow").toBeNamed("red")

Will both fail the test and print out the message you would expect:

expected foo to be red but was yellow
Error: expected foo to be red but was yellow
    at stack (http://localhost:7357/testem/jasmine2.js:1293:17)
    at buildExpectationResult (http://localhost:7357/testem/jasmine2.js:1270:14)
    at Spec.Env.expectationResultFactory (http://localhost:7357/testem/jasmine2.js:484:18)
    at Spec.addExpectationResult (http://localhost:7357/testem/jasmine2.js:260:46)
    at Expectation.addExpectationResult (http://localhost:7357/testem/jasmine2.js:442:21)
    at Expectation.toBeNamed (http://localhost:7357/testem/jasmine2.js:1209:12)
    at Object.<anonymous> (http://localhost:7357/generated/js/spec.js:22:10)
    at attemptSync (http://localhost:7357/testem/jasmine2.js:1510:12)
    at QueueRunner.run (http://localhost:7357/testem/jasmine2.js:1498:9)
    at QueueRunner.execute (http://localhost:7357/testem/jasmine2.js:1485:10)

Current Tags

  • 0.0.4                                ...           latest (4 years ago)

3 Versions

  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 3
Last Month 11
Dependencies (2)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |