karma-jasmine

Unit testing Javascript anonymous functions

不打扰是莪最后的温柔 提交于 2020-01-05 08:57:21
问题 I have a few anonymous functions inside of a $scope function in my application. These are anonymous because I only ever need them to run one time right when the page loads (which they do). Inside of those anonymous functions I'm setting a $scope.itemSuccess variable to true and return; when certain specifications are met (not important). These anonymous functions also increment a $scope.counter; I'm not sure how to target these anonymous functions inside of a jasmine unit test. I need to make

How to test apps separately in a multi-app project?

谁说我不能喝 提交于 2020-01-05 08:51:33
问题 I have a multi app project. I can run the apps separately with the following command: ng serve --app <appName> -aot . In the other hand I would like to be able to run the test for each app separately the same as running them. e.g. ng test --app <appName> --sm=false But it's doesn't work as expected. The test started always by the first app in the file system. I have been searching and found out that I might have to change to configuration of the angular-cli.json - Proposal: app-specific karma

How to test Angular 1.6 component with injected service?

情到浓时终转凉″ 提交于 2020-01-05 08:10:27
问题 I want to test my Angular component which is syntactically based on John Papa's styleguide: 'use strict'; angular.module('MyModule') .component('MyCmpnt', MyCmpnt()) .controller('MyCtrl', MyCtrl); function MyCmpnt() { return { restrict: 'E', templateUrl: 'myPath/myTemplate.html', bindings: { foo: '=', bar: '<' }, controller: 'MyCtrl', controllerAs: 'vm' }; } MyCtrl.$inject = ['MyService']; function MyCtrl (MyService) { // controller logic } As you can see I want to inject MyService into the

jasmine unit tests for datetimepicker click event function

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 07:18:21
问题 Can any body suggest to write test case for this code which is in Jquery $('#issueDateSpan').click(function(event) { event.preventDefault(); $('#datetimepickerIssue').data('DateTimePicker').show(); }); 来源: https://stackoverflow.com/questions/39632316/jasmine-unit-tests-for-datetimepicker-click-event-function

karma-webpack : Module name has not been loaded yet for context : use require([])

怎甘沉沦 提交于 2020-01-05 04:16:06
问题 I'm new to Jasmine/Karma unit testing for JavaScript applications. I'm trying to implement it in my current project which is using Angular 1.4.12 and Webpack 1.13.1 for bundling. My folder structure is as follows: The index.js file inside 'core' is trying to require various other modules which are required for Webpack bundling. The file looks like this: require('../../bower_components/font-awesome/css/font-awesome.min.css'); require('../../bower_components/bootstrap/dist/css/bootstrap.min.css

unit test angular service not able to reach function inside service + jasmine

不想你离开。 提交于 2020-01-04 05:32:27
问题 I have written some service in angular. Check this PLUNKER. Injecting CommonService, $rootRouter, ModalService in RouteService . I am stuck with unit testing these services. You can see sample spec file at PLUNKER. EDIT: Whatever test I have at plunker are not working as expected. Am not sure what I am doing wrong. How to test goTo and getActivePage methods in RouteService ? How to test getProperty and setProperty methods in CommonService ? Here is code. First service is RouteService 'use

Jasmine.js Testing - spy on window.navigator.userAgent

落爺英雄遲暮 提交于 2020-01-03 16:38:11
问题 I need to find the way to change userAgent value. I tried to spyOn the window.navigator.userAgent . But that's not helping. JS : @Injectable() export class DetectBrowserService { browserIE: boolean; constructor() { this.browserIE = this.detectExplorer(); } public detectExplorer() { const brows = window.navigator.userAgent; const msie = brows.indexOf('MSIE '); if (msie > 0) { // IE 10 or older => return version number return true; } } } Spec : it('should test window.navigator.userAgent', () =>

Jasmine.js Testing - spy on window.navigator.userAgent

末鹿安然 提交于 2020-01-03 16:37:26
问题 I need to find the way to change userAgent value. I tried to spyOn the window.navigator.userAgent . But that's not helping. JS : @Injectable() export class DetectBrowserService { browserIE: boolean; constructor() { this.browserIE = this.detectExplorer(); } public detectExplorer() { const brows = window.navigator.userAgent; const msie = brows.indexOf('MSIE '); if (msie > 0) { // IE 10 or older => return version number return true; } } } Spec : it('should test window.navigator.userAgent', () =>

Jasmine: How to see the reports in the browser?

前提是你 提交于 2020-01-03 09:47:32
问题 THE SITUATION: I am currently running AngularJs unit tests in the console. I open the folder in the console and i run karma start and check the result of the tests in the console. I would like to see the results in the browser but I cannot see them so far. All i can see is this: THE QUESTION: How can i see the reports of the tests in the browser? The proper plugin should be karma-jasmine-html-reporter right? THE CONFIGURATION: karma.conf.js: frameworks: ['jasmine'], files: [ 'bower_components

Angular 2 Integration Testing (Unit Test Style)

孤街浪徒 提交于 2020-01-03 09:05:43
问题 Is it possible to test an angular app with its testing framework (primarily designed for unit testing) against a real backend? Let's say E2E Testing with Protractor is not an option for me, but still i want to do some integration tests within my Unit Test Environment with Karma. I really have trouble finding examples or even a statement if it's possible or not using Jasmine and the testing libs of angular 2. I know, that this isn't supposed to be best (or even just a good) practice, but that