I know the e2e tests for angular have a beforeEach for individual tests...but I'm looking for a level up for the entire suite. Anyone know a way to run a block of code before the entire test suite is executed?
Angular e2e / Karma - Before Suite block?
1.2k views Asked by OnResolve At
2
There are 2 answers
0
tarrball
On
I needed to do this to run a bunch of tests that required a user be logged in, so I created a file karma.suiteInitialize.js with the following code:
(function() {
'use strict';
angular
.module("app")
.run(testInitialize);
testInitialize.$inject = ['userService'];
function testInitialize(userService) {
userService.setUser({ UserName: 'Test user'});
// if (userService.isLogged())
// console.log("Test user logged in");
}
})();
and then just added it to karma.config.js immediately after the app files like:
files: [
'../Scripts/angular.js',
'../Scripts/angular-mocks.js',
'../Scripts/angular-route.js',
'../Scripts/angular-filter.js',
'../Scripts/angular-resource.js',
'../Scripts/angular-scroll.min.js',
'app/app.module.js',
'app/**/*.js',
'karma.suiteInitialize.js',
'tests/**/*.js',
'app/**/*.html'
]
..and that was all it took. This doesn't reduce the number of calls to log the user in (it still happens for every test), but it does make it convenient.
Related Questions in ANGULARJS
- Angular Show All When No Filter Is Supplied
- Using pagination on a table in AngularJS
- State with different subviews
- Getting and passing MVC Model data to AngularJS controller
- Implementing prerender.io middleware in sails.js
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- AngularJS, Google App Engine and URLrewrite
- send data from table to another page into forms
- How to write tests for classes with inheritance
- angularJS sending OPTIONS instead of POST
- Receiving POST from external application in AngularJS
- Metaprogramming AngularJS Filters
- Reload List after Closing Modal
- Why is my angularjs site not completely crawlable?
- Why is separation of JavaScript and HTML a good practice?
Related Questions in INTEGRATION-TESTING
- TeamCity create arbitrary directory structure on agent
- Integration testing the entity framework - separate the seed method call only for PROD -
- Test case for WCF REST Service
- Spring MockRestServiceServer handling multiple requests to the same URI (auto-discovery)
- Rails 4 Integration Testing Arrays not present in json object inside controllers
- Is there a testing framework that works with threads in Python?
- Dealing with TargetWithLayout in XUNIT
- database restore for integration tests with phpunit
- How to initialize test class before context initialization while Spring testing?
- What should a controller integration test assert
- Maven and python integration test set up
- Amazon Kinesis + Integration Tests
- continuous integration - build separated projects or build all in one?
- How to deploy WildFly datasource with Arquillian?
- Stubbing method in ActionDispatch::IntegrationTest
Related Questions in KARMA-RUNNER
- Working with karma and BrowserStack
- how to mock $state.params in jasmine unit testing
- Testing javascript using d3 with Karma
- Karma Coverage and Babel+Browserify Preprocessing
- test service call with success () , error () in jasmine
- Accessing scope.variables inside a function in jasmine
- Testing methods returning promise using jasmine
- Testing an AngularJS directive with isolated scope
- Can't redefine service defined as constant
- Speed up tests run in Chrome
- Organizing unit tests in angular app
- lodash npm distribution in browser
- how to test service property call
- Karma tests reporting fast runs, but actually running slow
- Writing the most basic Unit test in Angular 2?
Related Questions in TEST-SUITE
- Export test Cases from MTM (Microsoft Test Manager)
- junit 4 all pairwise permutations of test methods
- JUnit - Ignore test when part of Suite
- How to access variables in a test case class from a test suite runner class
- unittest.TestSuite runs previously loaded tests in addition to currently added tests
- Create global variable in Test Suite accessible by all JUnit Test
- second test of test suite fails (browser doesn't opens)
- Run single testsuite with Gradle Java
- Can I get statistics for test cases steps inside robot framework?
- TFS Test Plans Merge from different Projects
- Test suite for GIF containing images using rarely used features
- Test Suites for testing comet server functionality through PHP
- Angular e2e / Karma - Before Suite block?
- Do JUnit test suites support custom annotations?
- Fitnesse : How to run specific tests across multiple Test suites
Related Questions in ANGULARJS-E2E
- A Jasmine spec timed out. Resetting the WebDriver Control Flow - when redirect to new page
- Unable to click button in angular application using angular e2e testing
- Waiting for Ionic Loading dialogs with Protractor
- How to test a flicker div in AngularJS using protractor
- RequireJS modules in Protractor specs. Is it possible?
- Protractor - Where to use browser.waitForAngular()
- Mocking API with httpBackend [Protractor]
- Protractor - Wait for async promise before doing next
- Mocking API with usage of httpBackend and Protractor
- What is the benefit of using protractor for applications non angular?
- Protractor - Page Object is not updating when the DOM elements are changed
- Mocking a server response
- running protractor test with teamcity
- $document.injector is not a function in Karma E2E Tests
- Using Protractor to select nav menu items
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
If you don't mind the block being run for every test in your suite you could nest your tests and have a
beforeEachat the highest level, e.g.,However, the main beforeEach will execute before every it block in the entire suite. If you want the code to be executed only once then this isn't the solution for you.