Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pending() in beforeEach does not stop execution #1579

Closed
webmaster128 opened this issue Jul 17, 2018 · 5 comments
Closed

pending() in beforeEach does not stop execution #1579

webmaster128 opened this issue Jul 17, 2018 · 5 comments
Labels

Comments

@webmaster128
Copy link

Expected Behavior

Calling pending() in beforeEach should allow the user to prevent further execution of a spec.

Current Behavior

Calling pending() in the spec itself stops spec execution while calling it in beforeEach only marks the test as pending but does not stop execution.

Suite that reproduces the behavior (for bugs)

./node_modules/.bin/jasmine --random=false dummy.spec.js of

describe("pending in body", () => {
  it("should not explode", () => {
    pending("Stop execution or things will explode");
    console.log("body: boom!");
  });
});

describe("pending in beforeEach", () => {
  beforeEach(() => pending("Stop execution or things will explode"));

  it("should not explode", () => {
    console.log("beforeEach: boom!");
  });
});

prints

Started
*beforeEach: boom!
*

Pending:

1) pending in body should not explode
  Stop execution or things will explode


2) pending in beforeEach should not explode
  Stop execution or things will explode

2 specs, 0 failures, 2 pending specs
Finished in 0.009 seconds

Context

In our environment we want to selectively stop test execution for client-server tests when server is not there. Marking the spec as pending is not sufficient since a complex initialization is started that leads to some very hard to debug exceptions in afterAll.

Your Environment

  • node v8.10.0
  • jasmine 3.1.0
@slackersoft
Copy link
Member

The current mechanism for this is the --stop-on-failure CLI argument. This is also configurable in your jasmine.json as stopSpecOnExpectationFailure. If this isn't working with pending() we definitely need to fix that.

I would also be happy to review a pull request that makes pending() always behave as if stopSpecOnExpectationFailure is set.

Hope this helps. Thanks for using Jasmine!

@johnjbarton
Copy link
Contributor

We hit a similar issue, but I am confused by the answer here.

If we set stopSpecOnExpectationFailure, the pending() will work when called in beforeAll()?

@slackersoft
Copy link
Member

stopSpecOnExpectationFailure should only affect what pending does in a beforeEach not a beforeAll. Jasmine runs a beforeAll as part of a suite, where a beforeEach is run as part of a spec.

@johnjbarton
Copy link
Contributor

Thanks, so what should pending() mean in beforeAll()? I believe the intention was for the entire suite to be set pending, but that was not the result.

@slackersoft
Copy link
Member

A call to pending() from a beforeAll should mark all specs within the describe as pending, but Jasmine may still run them as long as their status continues to be pending after execution. This should be similar to how calling pending works within a beforeEach without stopSpecOnExpectationFailure (or oneFailurePerSpec) enabled.

This may be a future looking statement, I'm not sure that Jasmine has any tests that assert on the interaction of pending and beforeAll. If this isn't the case currently, I would also be happy to review a pull request to at least define that functionality. Given the current mechanisms for handling exiting early, I'm not sure what the effort would be to make pending also exit the describe early without exiting the entire suite.

rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 1, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
bcaudan added a commit to DataDog/browser-sdk that referenced this issue Nov 19, 2019
cf jasmine/jasmine#1579, when marking a spec as pending in before each without `oneFailurePerSpec`, spec will continue its execution silently.
this behavior generated random failure due to inconsistent state:
```
logger session
    ✗ should renew on activity after expiration
	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Error: Mock clock is not installed, use jasmine.clock().install()
	    at <Jasmine>
	   at Anonymous function (eval code:17:9)
	    at <Jasmine>
```
bcaudan added a commit to DataDog/browser-sdk that referenced this issue Nov 19, 2019
cf jasmine/jasmine#1579, when marking a spec as pending in before each without `oneFailurePerSpec`, spec will continue its execution silently.
this behavior generated random failure due to inconsistent state:
```
logger session
    ✗ should renew on activity after expiration
	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Error: Mock clock is not installed, use jasmine.clock().install()
	    at <Jasmine>
	   at Anonymous function (eval code:17:9)
	    at <Jasmine>
```
bcaudan added a commit to DataDog/browser-sdk that referenced this issue Nov 20, 2019
* ✅ [unit] ensure that global objects are always clean

fix ''getInternalContext' not yet available, please call '.init()' first.' warning

* ✅ [unit] stop spec execution on failure/pending

cf jasmine/jasmine#1579, when marking a spec as pending in before each without `oneFailurePerSpec`, spec will continue its execution silently.
this behavior generated random failure due to inconsistent state:
```
logger session
    ✗ should renew on activity after expiration
	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Unable to get property 'notify' of undefined or null reference thrown

	Error: Mock clock is not installed, use jasmine.clock().install()
	    at <Jasmine>
	   at Anonymous function (eval code:17:9)
	    at <Jasmine>
```

* trigger ci
BenoitZugmeyer added a commit to DataDog/browser-sdk that referenced this issue Nov 4, 2020
With this value to false, the tests are kind of failing on IE where we
mark some test suite as "pending" in the `beforeEach` callback.  This is
a known issue in Jasmine jasmine/jasmine#1579
bcaudan pushed a commit to DataDog/browser-sdk that referenced this issue Nov 5, 2020
* [RUMF-759] use RUM_EVENT_COLLECTED events to test sent events

With the newly introduced RUM_EVENT_COLLECTED and
RUM_EVENT_V2_COLLECTED, we can test for generated events without the
need to retrieve them from a mocked server. This simplifies the unit
tests a bit.

* [RUMF-759] introduce withConfiguration

This new helper allows to edit the configuration before any
`beforeBuild` callback is invoked.  It slightly simplifies the FF
edition.

* [RUMF-759] replace the performance observer stub with a spy

* [RUMF-759] use an object for beforeBuild

This will allow us to provide more data for beforeBuild callbacks

* [RUMF-759] allow to return a cleanup callback

A few spec helper methods that could be inlined in their spec are using
a cleanup function. To allow moving them, we add a way to define a
cleanup function in beforeBuild callbacks.

* [RUMF-759] inline withViewCollection in trackViews spec

* [RUMF-759] inline withActionCollection in the trackActions spec

* [RUMF-759] inline withPerformanceCollection in the performanceCollection spec

* [RUMF-759] inline withParentContexts() in parentContexts spec

* [RUMF-759] inline withRum in rum spec

* [RUMF-759] inline withInternalContext in internalContext spec

* [RUMF-759] inline withAssembly / withAssemblyV2 in assembly specs

* restore oneFailurePerSpec: true

With this value to false, the tests are kind of failing on IE where we
mark some test suite as "pending" in the `beforeEach` callback.  This is
a known issue in Jasmine jasmine/jasmine#1579

* 👌 return an object with a `stop` method for cleanup
@sgravrock sgravrock added 4.0 and removed help needed labels Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants