Jasmine Show archive.org snapshot is a great way to unit test your JavaScript components without writing an expensive end-to-end test for every small requirement.
After we integrated Jasmine into a Rails app we often add an E2E test that opens that Jasmine runner and expects all specs to pass. This way we see Jasmine failures in our regular test runs.
RSpec
In a feature spec you can run Jasmine specs like this:
scenario 'Jasmine tests' do
visit test_jasmine_path
expect(page).to have_content('finished in') # wait for all tests to finish
expect(page).not_to have_css('.jasmine-failed .jasmine-description') # better error messages
expect(page).to have_css('.jasmine-bar.jasmine-passed') # safer check
end
Cucumber
In Cucumber you can run Jasmine specs like this:
Scenario: Jasmine tests
When I run Jasmine tests
Then all specs should have passed
When 'I run Jasmine tests' do
visit test_jasmine_path
end
Then 'all specs should have passed' do
expect(page).to have_css('.jasmine-version'), 'Failed to load Jasmine page'
using_wait_time 60 do
expect(page).to have_content('finished in') # patiently wait for all tests to finish
end
# The above check will wait until tests are finished; once they are, we want
# to show fails early
using_wait_time 0 do
failed_specs = page.all('.jasmine-failed .jasmine-description').map(&:text)
puts 'Failed Jasmine specs:' if failed_specs.any?
failed_specs.each do |description|
puts "* #{description}"
end
expect(failed_specs.size).to eq(0), "Some Jasmine Specs failed (see above)"
expect(page).to have_css('.jasmine-bar.jasmine-passed') # safer check
end
end
Posted by Henning Koch to makandra dev (2021-10-13 11:30)