
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
jasmine-precondition
Advanced tools
A Jasmine instruction to ease setting up asynchronous pre-conditions before, during and after tests
A Jasmine instruction to ease setting up asynchronous pre-conditions before, during and after tests
Since Jasmine 2.0, the runs, waits, and waitsFor methods have been removed in favor of allowing functions run as part of the spec to receive and invoke a done callback. This new approach is described at Upgrading Jasmine - Asynchronous Specs.
The done callback works great for asynchronous features with a callback (such as AJAX, jQuery animations or anything else with promises). However, there are yet other asynchronous features that will complete on their own and would be using waitsFor before Jasmine 2.0, like rendering Google Maps, images or anything else that can change both the DOM and the CSSOM.
While it is utterly possible to re-implement waitsFor I believe that Jasmine 2.0 direction is more towards stepping away from this idea and instead taking more advantage of done callbacks, like putting one it block as a pre-condition for another.
Thus, the preCondition instruction defined here will simply poll a given conditional function at a certain time interval, and once its condition is met the callback done will be fired off.
npm install jasmine-preconditionnpm install karma-jasmine-preconditionpreCondition(condition, done, interval);
where:
condition: a conditional function that shall only return true when the condition you are expecting for is met.done: the done callback from beforeEach, it or afterEach must be passed here.interval (optional): a time interval in milliseconds between two condition executions. Default is 100.describe('the preCondition instruction', function () {
var counter1 = 0,
counter2 = 0,
interval;
beforeEach(function(done) {
interval = setInterval(function(){
counter1 += 100;
}, 100);
preCondition(function() {
return counter1 >= 500;
}, done, 100);
});
it('should only get executed when counter1 is 500', function (done) {
expect(counter1).toBe(500);
preCondition(function() {
counter2 += 200;
return counter2 === 1000;
}, done, 100);
});
it('should only get executed when counter2 is 1000', function () {
expect(counter2).toBe(1000);
});
afterEach(function(){
clearInterval(interval);
});
});
FAQs
A Jasmine instruction to ease setting up asynchronous pre-conditions before, during and after tests
The npm package jasmine-precondition receives a total of 8 weekly downloads. As such, jasmine-precondition popularity was classified as not popular.
We found that jasmine-precondition demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.