Giter Site home page Giter Site logo

Comments (10)

bitliner avatar bitliner commented on May 21, 2024

I solved adding ng-scenario to to karma-config.js

frameworks:['ng-scenario','jasmine'],

from karma-jasmine.

ponmani avatar ponmani commented on May 21, 2024

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




{{message}}

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.

vojtajina avatar vojtajina commented on May 21, 2024

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.

ponmani avatar ponmani commented on May 21, 2024

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.

WayneYe avatar WayneYe commented on May 21, 2024

@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.

sylvain-hamel avatar sylvain-hamel commented on May 21, 2024

@WayneYe I think your have to use two different karma.conf.js files. One for unit tests and one for 2e2.

from karma-jasmine.

WayneYe avatar WayneYe commented on May 21, 2024

@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.

sylvain-hamel avatar sylvain-hamel commented on May 21, 2024

@WayneYe I don't know then. I'm still new to the project.

from karma-jasmine.

vojtajina avatar vojtajina commented on May 21, 2024

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.

WayneYe avatar WayneYe commented on May 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.