Commit Graph

31 Commits

Author SHA1 Message Date
Steve Gravrock cca6b2aa07 Adopt forbidDuplicateNames: true in jasmine-core's own tests 2025-09-15 18:38:09 -07:00
Eradev 4732012f1c toHaveNoOtherSpyInteractions implementation 2025-01-10 21:05:12 -05:00
Steve Gravrock 1f1e1209d2 Merge branch 'add_toBeNullish' of https://github.com/MattMcCherry/jasmine
* Merges #2045 from @MattMcCherry
2024-12-12 17:30:55 -08:00
Matt McCherry 36dd6b07d1 add integration test for a falsy value 2024-12-10 11:39:44 +00:00
Alex Yorkovich 1805337424 Added new toHaveClasses matcher; tests included 2024-12-04 12:20:15 -06:00
Matt McCherry 580323c221 run prettier and fix tests 2024-12-02 10:34:55 +00:00
Matt McCherry d9286c549f add integration test for toBeNullish 2024-12-02 10:34:55 +00:00
Steve Gravrock 39f9c2e1a0 Don't attach spec helpers to the env 2023-08-26 11:52:26 -07:00
Steve Gravrock 2272f9aead Parallel: run our own specs in parallel 2022-09-17 11:35:03 -07:00
Steve Gravrock c24b2f5a73 Converted some integration specs to async/await 2022-05-14 12:05:53 -07:00
Steve Gravrock 1166d10e43 Use const/let in specs, not var 2022-04-16 13:41:44 -07:00
Steve Gravrock 482dc883eb Check for unused vars and params in specs 2022-04-16 10:58:25 -07:00
Nito Buendia 7b01003d0b Add specs for the new toHaveSpyInteractions matcher 2022-02-16 21:11:42 +08:00
Steve Gravrock fe0a83ba87 Removed support for Internet Explorer 2021-07-23 21:46:15 -07:00
Steve Gravrock dbc1a0aa56 Added expectAsync(...).already
* Causes async matchers to immediately fail if the promise is pending
* Fixes #1845
2021-06-23 20:13:01 -07:00
Steve Gravrock d27bb8fa96 Run Prettier on all files 2020-09-29 18:05:38 -07:00
Steve Gravrock 00feef8632 Fixed global error handler stack corruption in Jasmine's own tests 2020-09-02 14:01:57 -07:00
Steve Gravrock 4e2f703615 Check for syntax and standard library objects that don't work in IE 2020-07-01 17:34:59 -07:00
Maksym Kobieliev 0f6ebaa784 Merge branch 'master' into feat/to-have-been-called-once-with 2020-04-14 22:08:13 +03:00
Gregg Van Hove ec3ebcb7bb Clean up toHaveSize 2020-03-18 08:13:21 -07:00
Francois Wauquier c521b4d47c toHaveSize 2020-03-18 08:13:10 -07:00
Maksym Kobieliev e13fd13529 Add a toHaveBeenCalledOnceWith matcher 2020-03-13 20:41:24 +02:00
Steve Gravrock c2ada1af95 Merge branch 'custom-object-formatters' into cof-merge-candidate 2020-02-11 13:51:17 -08:00
Steve Gravrock 25816a6e77 Added support for custom object formatters
Custom object formatters allow users to customize how an object is
stringified in matcher failure messages. This can already be done by
adding a `jasmineToString` method to the objects in question. But
it's not always desirable or possible to do that, particularly when
objects of a given "type" do not inherit from a specific prototype.
For instance, suppose a web service returns a list of foos that are
deserialized from JSON, e.g.:

   { fooId: 42, /* more properties */ }

The only way to define `jasmineToString` on those is by writing code to
add it to each instance at runtime. But a custom object formatter can
recognize that the object it's looking at is a foo and format it
accordingly:

   jasmine.addCustomObjectFormatter(function(obj) {
      if (typeof obj.fooId !== 'number') {
            return undefined;
        }

        return '[Foo with ID ' + obj.fooId + ']';
    });

Unlike `jasmineToString`, custom object formatters are scoped to a
particular spec or suite and don't require any changes to the code
under test.
2020-02-10 17:26:00 -08:00
Steve Gravrock dec67bd535 Don't require matchers and asymmetric equality testers to pass custom object formatters back to Jasmine
This makes it easier to write high quality matchers and asymmetric equality
testers, and is also a step toward supporting custom object formatters.

Previously, Jasmine passed custom object formatters as the second argument
to matcher factories and as and the second argument to asymmetric equality
testers' `asymmetricMatch` method. Matchers and asymmetric equality testers
were responsible for passing the custom object formatters to methods like
`matchersUtil#equals`:

  function toEqual(util, customEqualityTesters) {
    return {
      compare: function(actual, expected) {
        // ...
        result.pass = util.equals(actual, expected, customEqualityTesters, diffBuilder);

And:

  ArrayContaining.prototype.asymmetricMatch = function(other, customTesters) {
    // ...
    for (var i = 0; i < this.sample.length; i++) {
      var item = this.sample[i];
      if (!j$.matchersUtil.contains(other, item, customTesters)) {
        return false;
      }
    }

With this change, that is no longer necessary. Matchers and asymmetric
equality testers can ignore the existence of custom equality testers and
still fully support them:

  function toEqual(util) {
    return {
      compare: function(actual, expected) {
        // ...
        result.pass = util.equals(actual, expected, diffBuilder);

And:

  ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
    // ...
    for (var i = 0; i < this.sample.length; i++) {
      var item = this.sample[i];
      if (!matchersUtil.contains(other, item)) {
        return false;
      }
    }

The old interfaces are still supported, for now, but will be deprecated
in a future commit and removed in the next major release after that.

In addition to making matchers and custom equality testers simpler,
this change sets the stage for adding support for custom object
formatters. Those will be architecturally similar to custom equality
testers, and by injecting a `MatchersUtil` instance everywhere we can
add them without requiring user code to pass them around as used to be
the case with custom object formatters.
2020-02-10 17:25:50 -08:00
Steve Gravrock 83b336d9d1 Merge branch 'matcher-integration-tests' 2020-02-06 18:16:06 -08:00
Steve Gravrock 7f392d188e Don't leak global error handlers between Jasmine's own tests 2020-01-20 10:18:29 -08:00
Steve Gravrock 795a80ec66 Added integration tests for asymmetric equality testers 2019-11-17 15:11:53 -08:00
Steve Gravrock 68f25a758d Don't create env instances in beforeEach 2019-09-11 13:31:01 -07:00
Steve Gravrock 2d3ac38df8 toBeRejectedWithError can expect the error to be Error, not just a subtype 2019-09-06 14:17:52 -07:00
Steve Gravrock 5a219da848 Added basic integration tests for all built-in matchers 2019-09-06 14:10:16 -07:00