In what order should you include Jasmine scripts? - jasmine

No where in the documentation does it tell you which scripts to include in which order. I would like to print to the console because I am running jasmine inside PhantomJS. What files should I use for this?
I'm trying:
bootstrap.js
console.js
jasmine.js
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(console.log));
but it gives
TypeError: 'undefined' is not a constructor (evaluating 'new jasmine.ConsoleReporter(console.log)')

jasmine.js needs to come before console.js, as console.js adds ConsoleReporter() as a method to the jasmine object.

Look at the included sample btml runner. I found that any add on must load after boot.js. For example, Jasmine-jquery and teamcity reporters. These usually attach themselves to the global Jasmine object which is configured in boot.

Related

Cypress with Jasmine

We are in a process of migrating existing Protractor scripts(with Jasmine Framework) to Cypress.
I would like to know if we can use the Jasmine in Cypress also. As, Cypress by default uses Mocha.., so need a clarification if we can install Jasmine dependences along with Cypress to define the tests with Framework.
I don't think so. Cypress modifies/patches the Mocha hooks like beforeEach() and also the chai expect() to work with their framework.
Is there anything about Jasmine that you don't get out of the box with Cypress? I believe the expect() syntax may be different, if you have too many Jasmine-style expectations to change you may be able to add custom Chai expressions so that they work without modification.

Jasmine - How to get only specs within current suite?

I have multiple suites(describes) inside a spec.js file. I would like to implement jasmine-fail-fast and fail only one suite(single describe block) at a time and proceed with the rest in the spec.js file. The available plugin does not support this feature as it tries to get all specs inside the spec.js file at a time.
Is there any workaround for this ? TIA

UglifyJS2 call minify function programmatically

I would like to know if I can call the minify main function programmatically.
I am able to run the same code as defined in compress, however replacing UglifyJS.Compressor with UglifyJS.minify does not work.
This is because I would like to pass the same options defined in the README of UglifyJS2, instead of the ones in compress.
Please note that I am running the code in Nashorn, and not in Node.js so that would be similar to a browser environment.
This is a work in progress: see this issue and this PR.

Karma-jasmine and beforeAll/afterAlll hooks in Jasmine?

I would like to be able to use beforeAll and afterAll hooks in my application, but I am unable to do so with karma-jasmine. I'm aware I need to modify my boot.js file, but that's provided by the library. How would I set a beforeAll callback in the karma.conf.js file?
You cannot set a callback in karma.conf.js... The Karma Docs show all possible configuration options and there is no option to set a callback.

Stop jasmine test after first expect fails

I'm familiar with python unittest tests where if an assertion fails, that test is marked as "failed" and it moves on to other tests. Jasmine on the other hand will continue through all expects even if the one of them fails. How can I make Jasmine stop processing a test after the first expectation fails?
it ("shouldn't need to test other expects if the first fails", function() {
expect(array.length).toBe(1);
// don't need to check this if the first failed.
expect(array[0]).toBe("foo");
});
Am I thinking about it wrong? I have some tests with lots of expect's and it seems like a waste to show all the stack traces when only the first is wrong really.
#Gregg's answer was correct for the latest version of Jasmine at that time (v2.0.0).
However, since then, this new feature was added in v2.3.0:
Allow user to stop a specs execution when an expectation fails (Fixes #577)
It's activated by adding throwFailures=true to the query string of the runner page, eg:
http://localhost:8000/?throwFailures=true
Jasmine doesn't support failing early, in a single spec. The idea is to give you all of the failures in case that helps figure out what is really wrong in your spec.
Jasmine has stop on failure feature and you can check it here:
https://plnkr.co/plunk/Ko5m6MQz9VUPMMrC
This starts jasmine with oneFailurePerSpec property.
According to the comments of https://github.com/jasmine/jasmine/issues/414 I figured out that 2 solutions exists for this:
https://github.com/radialanalytics/protractor-jasmine2-fail-whale
https://github.com/Updater/jasmine-fail-fast
I just started to use the protractor-jasmine2-fail-whale because it seems to have more features. Although to take screenshots in case of test failures I currently use protractor-jasmine2-html-reporter.
I'm using Jasmine in Appium (a tool to test React Native apps).
I fixed the issue by adding stopSpecOnExpectationFailure=true to Jasmine configs
jasmine v3.8.0 & jasmine-core v3.8.0

Resources