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
Related
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 some test set up code that I need to run before any Capybara tests that are running JavaScript with the #javascript tag. I don't want the code to run the rest of the time since this test set up is expensive in terms of system resources and cognitive load.
I've searched the documentation extensively and was unable to find any examples of running arbitrary ruby before tests based in tagging. Can anyone help me out?
Edit: after thinking about this some more, I only need the code to run once before any tests are run, so this is probably a simpler problem then I first described.
Since you're asking about an #javascript tag I'm assuming you're talking about Cucumber driven tests, if you're not then please clarify.
To run code before a test you use Before
Before('#javascript') do
# any code here will get run before each test tagged with #javascript
end
To make it only run that code once you'd need to use a global variable
Before('#javascript') do
$already_run ||= false
return $already_run if $already_run
# code here will get run once before the first test tagged #javascript
$already_run = true
end
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?
I have a mountable engine that provides Javascript assets to the main Rails App, but while I try testing AJAX calls (provided by the Javascript I just mentioned) in Capybara and Spec. The database doesn't seem to update.
Because of the cluster nature of testing, I can't have a clear understanding of what exactly is being run and loaded on the Dummy App. I was thinking about running the Dummy App as a standalone app and verify what is being rendered via the web browser (sort of manually checking things out). But that wasn't possible because of a Gemfile not found error every time I try running 'rails s' within the spec/dummy folder.
So my question: is there another way to check why the AJAX calls are not working in my test cases(although when I run the app normally the AJAX calls are working just fine) or does anyone know how to run the dummy app as a standalone rails App?
Thanks
The default settings of Capybara doesn't allow AJAX calls.....I had to modify the driver used by Capybara in the spec_helper.rb by adding the following:
Capybara.default_driver = :selenium