I'm unit testing my Javascript (AngularJS) app using Karma, Mocha and Chai. This all works fine, however in Mocha's doc I see a lot of cool stuff like custom reporters and text diffs on failures. How can I use these features when not using Mocha directly but trough karma-mocha?
As an example, how could I use Mocha's "Landing Strip" reporter instead of Karma's default "dots" or "progress" reporters?
Related
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.
Is there a way to prevent karma-jasmine-html-reporter aka kjhtml from reporting skipped/pending tests?
I run some tests using fit and fdescribe and I want to only see results for the selected tests, however, the reporter is always displaying all tests from the suite.
Apparently, yes, there's a way to that with Jasmine (starting from v3.3.0). I've been able to do that in an Angular project. In the test.ts I've put something like:
jasmine.getEnv().configure({ hideDisabled: true });
Official documentation here: https://jasmine.github.io/api/3.5/Configuration.html.
I was at the point where I felt familiar with feature and unit tests in Laravel. But recently I created a new project and discovered Laravel Dusk. After its installation there now also is a Browser directory where I can put my tests in. But now I'm confused, what is the difference between a feature and a browser test? For example where would I put tests like
a_visitor_can_signup()
the_index_page_shows()
the_contact_form_validates()
..
Is browser behavior (interaction) a typical browser test? And would request-like tests like testing endpoints for a HTTP status 200 to ensure nothing is broken at that point be feature tests?
A feature test would be a test, which tests a feature product may have asked for while a browser behavior test would test a specific action.
Feature Test: User can sign up.
Browser Behavior Test: When user clicks the button it submits the form.
Basically, the feature test is the end-to-end test. While the browser behavior test is a unit or integration test testing a single behavior.
In general, you want to have unit tests—each of which test a single behavior. One main reason being maintainability.
For example, if testing a javascript form, you may have behavioral javascript tests like the following:
describe("form#user-profile", function(){
context("when a click event is triggered", function(){
describe("`foo` is called with arguments a, b and c", function(){
expect(foo).to.be.calledWith(a,b,c)
})
})
})
Which will read out as "form#user-profile, when a click event is triggered, foo is called with arguments a, b and c." This in essence is a unit test which tests a "browser behavior"
References
Mocha
Chai
Sinon
I would summarize like this:
If there is javascript involve in the test, use laravel dusk (browser test).
If there is none, stick to feature test.
I have a script that use Capybara to publish links in Google+. I would like to have tests to cover this functionality. Usually Capybara is using as a tool for writing Integration tests. In may case i need to test Capybara itself.
I see 3 possible ways:
stub capybara's method (but in this case i test nothing but just stubbed methods)
test capybara agains saved HTML/JS page (that will help me understand that i did not break anything during refactoring)
do not test at all (no comments here)
Have you ever faced such a problem?
If you register different drivers for your app and your test code, possibly manage the sessions manually depending on how you're using it in your app, and make sure you're careful with Capybaras setting's you should be able to go with option 2. You have to be careful with Capybaras settings because most of them are global so changing them for your tests will also change them for your app.
I've been following some tuts, they all seems to include some js file into the src folder and run it on a test Runner html.
I have a Web App running on localhost:9292, How can I test it? Say a really simple one, I want to test the title of the Web App is "My App", which not the title of the Test runner page.
There are no way to use phantomjs inside jasmine specs. You can use karma with jasmine to test localhost:9292 (set it in karma config file).
Here is a simple example how to test any web page with phantomjs. Hope it helps
https://github.com/mikach/phantomjs-test-runner