Comments (10)
I solved adding ng-scenario
to to karma-config.js
frameworks:['ng-scenario','jasmine'],
from karma-jasmine.
Hello bitliner.I used angular seed project adding extra simple login page. I added frameworks
frameworks:['ng-scenario','jasmine'], of my karma.conf.js. See below my karma.conf.js
login.html
Controller code
$scope.login = function () {
auth.login($scope.username, $scope.password)
.then(function () {
session.username = $scope.username;
$location.path('/index');
}, function (reason) {
$scope.message = reason;
});
};
e2e
.scenarios.js
describe('login', function () {
beforeEach(function () {
browser.get('index.html#/login');
});
it('should then be.', function () {
browser().navigateTo('/login');
var username = input('username').enter('steph');
console.log(username);
input('password').enter('steph');
element('#login').click();
expect(browser().location().url()).toBe("/index");
expect(element('#user').text()).toEqual('steph');
});
});
unit test
controllersSpec.js
it('should login', function () {
browser().navigateTo('/login');
input('username').enter('steph');
input('password').enter('steph');
element('#login').click();
expect(browser().location().url()).toBe("/index");
expect(element('#user').text()).toEqual('steph');
});
my karma.config.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['ng-scenario'],
files: [
'app/lib/angular/angular.js',
'app/lib/angular/angular-.js',
'test/lib/angular/angular-mocks.js',
'app/js/.js',
'test/unit/*.js'
],
exclude: [
'app/lib/angular/angular-loader.js',
'app/lib/angular/*.min.js',
'app/lib/angular/angular-scenario.js'
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
from karma-jasmine.
Guys, do not use "jasmine" and "ng-scenario" together. That won't work. These are two different frameworks with very similar syntax.
If you wanna write unit tests (low level, JS tests, asserting that some objects or functions work as expected), use Karma with Jasmine.
If you wanna write end-to-end test for an AngularJS app (such as, open my app, click on "OK" button, etc), use Protractor. You can also use Karma with "ng-scenario" runner, but it's deprecated.
from karma-jasmine.
Hi vojtajina,
I am beginner for karma unit testing. Please help me. You download angular seed project https://github.com/angular/angular-seed. Added Extra login page and controller.The page was username and password textfield. How to write karma unit test. Please send modified angular seed your project. Urgent please.
from karma-jasmine.
@vojtajina
Hi Vojta, simple question, without specifying "ng-scenario" in karma.conf.js, "browser" would be undefined, if we want to use karma+jasmine, and also, I have a few browser based test cases, what should I do please?
from karma-jasmine.
@WayneYe I think your have to use two different karma.conf.js files. One for unit tests and one for 2e2.
from karma-jasmine.
@sylvain-hamel Thanks for the reply! Buy even if I use two conf file, I still need Jasmine (or mocha, qunit, etc) to do assertions, I googled for hours but didn't find a example with the following things running together:
karma, jasmine 2.0 (done style async test), browser()
from karma-jasmine.
@WayneYe I don't know then. I'm still new to the project.
from karma-jasmine.
Did you read my comment above? (#10 (comment))
If you wanna test your app from a user point of view, do things like "open google.com", "type foo", "click a button", etc... that's what we call end2end test. Check out Protractor https://github.com/angular/protractor
Karma is for unit testing, where you test individual objects, whether they do what they are suppose to do. These tests run in a browser too. There is DOM and all the stuff. These tests are faster, but are not suitable for the entire app tests (stuff like navigating to a page), because Karma just loads a bunch of JavaScript files and runs that code.
from karma-jasmine.
@vojtajina Thanks for the reply, I missed your last sentence:) I realised it now and already working with protractor. Appreciate your splendid work on Karma, make it better!!
from karma-jasmine.
Related Issues (20)
- spec selection does not work anymore HOT 1
- DOMTestComponentRenderer.insertRootElement when mocking document.querySelectorAll HOT 1
- jasmine's failFast not working in 4.0.1
- Sends report before tests finish running HOT 1
- Unused packages detected in the karmajasmine project on Tag: v4.0.1 HOT 1
- Add CI/CD with GitHub Actions HOT 1
- specFilter causes timeout with large amount of tests HOT 1
- Jasmine 4 support? HOT 1
- Reestablish CI/CD with GitHub Actions HOT 1
- Duplicate error messages (reopen)
- Linting Should Run in Its Own Workflow
- Establish a Beta Release HOT 14
- Convert tools/integration-tests.sh to a cross-platform script HOT 3
- Update eslint-config-standard HOT 4
- Uncaught (in promise) Type Error: Cannot read properties of null (reading 'jasmineMessage') HOT 3
- Opening Context.html window raises an error for parentWindow.karma object "Cannot read property 'info' of undefined" HOT 1
- Support for Jasmine 5 HOT 2
- Add doc deprecation for karma-jasmine with recommendations
- Karma failing with CI/CD
- Incorrect link in 5.0.0 release notes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-jasmine.