jasmine

How to test code inside $(window).on(“load”, function() {}); in Jasmine

余生颓废 提交于 2020-01-15 04:20:29
问题 I have a javascript below, which appends a DIV on page load and hides it after 3 sec. var testObj = { initialize: function() { var that = this; $(window).on("load", function() { (function ($) { //Append Div $('body').append("<div>TEST</div>"); })(jQuery); that.hideAppendedDiv(); }); }, hideAppendedDiv: function() { //Hide appended Div after 3s setTimeout(function(){ $("div").hide(); }, 3000); } }; //call Initialize method testObj.initialize(); How to write Jasmine test cases for the methods

How to mock window.screen.width in Angular Unit Test with Jasmine

血红的双手。 提交于 2020-01-14 13:51:09
问题 I have a BreakpointService, which tells me - depending on the screen width - in which SidebarMode (closed - minified - open) I should display my Sidebar. This is the main part of the service: constructor(private breakpointObserver: BreakpointObserver) { this.closed$ = this.breakpointObserver.observe(['(min-width: 1024px)']).pipe( filter((state: BreakpointState) => !state.matches), mapTo(SidebarMode.Closed) ); this.opened$ = this.breakpointObserver.observe(['(min-width: 1366px)']).pipe( filter

Chutzpah and Jasmine 2.0 and RequrieJs

半腔热情 提交于 2020-01-14 10:08:34
问题 I'm having some bother getting Chutzpah to work with requireJs/jasmine 2.0. This method worked for version 1.3 but now for jasmine version 2.0 chutzpah has stopped picking up the tests. I upgraded chutzpah to 3.1.1 for the jasmine 2.0 support as well. I did have to make a small change to load jasmine from requireJs to make it work but I figured this shouldn't affect chutzpah as it was just loading the html. Here's the command I run for chutzpah. chutzpah.console.exe path/to/SpecRunner.html

Jasmine test simulate tab keydown and detect newly focused element

拈花ヽ惹草 提交于 2020-01-14 10:02:28
问题 I have a jasmine test where I have 2 input fields. I am focusing on an first input, then simulating a keydown on the 'tab' key, and expecting focus to be on the second input. Unfortunately this is not the case. The focus does not change from the first and my test is failing. How can this be fixed so the failing test passes? Fiddle of what I'm trying to test: http://jsfiddle.net/G2Qz3/1/ Fiddle of the failing Jasmine test: http://jsfiddle.net/mFUhK/4/ HTML: <input id="first"></input> <input id

Jasmine/PhantomJs spec runner

泄露秘密 提交于 2020-01-14 08:50:30
问题 I cannot get my test to run using phantomJs. gulp task var jasminePhantomJs = require('gulp-jasmine2-phantomjs'); gulp.task('test', function() { return gulp.src('./SpecRunner.html') .pipe(jasminePhantomJs()); }); SpecRunner.html <script src="lib/jquery.min.js"></script> <script src="lib/lodash.min.js"></script> <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script> <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script> <script type="text

Angular-Jasmine injecting a service into the test

限于喜欢 提交于 2020-01-14 04:40:06
问题 New to Jasmine, I am trying to instantiate my controller which has a list of dependencies (mainly the services I have written) and all the different ways I';ve tried haven't been right. Here is my controller: (function () { 'use strict'; angular.module('app.match') .controller('MatchController', MatchController); MatchController.$inject = ['APP_CONFIG', '$authUser', '$http', '$rootScope', '$state', '$stateParams', 'SearchService', 'ConfirmMatchService', 'MusicOpsService', 'ContentOpsService',

Uncaught ReferenceError: define is not defined

一曲冷凌霜 提交于 2020-01-14 04:10:29
问题 Thanks for any help you can offer. I have a Grails project that I'm trying to install Karma into. However, when I run ./gradlew build I get the following error: [x-10-105-56-234]SENG5199-twtr (BRANCH1) $ ./gradlew check :bowerInit UP-TO-DATE :nodeSetup UP-TO-DATE :bowerDependencies UP-TO-DATE :bowerConfig :bowerComponents UP-TO-DATE :bowerInstall UP-TO-DATE :compileJava UP-TO-DATE :compileGroovy UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :karmaInit UP-TO-DATE

Uncaught ReferenceError: define is not defined

烈酒焚心 提交于 2020-01-14 04:10:16
问题 Thanks for any help you can offer. I have a Grails project that I'm trying to install Karma into. However, when I run ./gradlew build I get the following error: [x-10-105-56-234]SENG5199-twtr (BRANCH1) $ ./gradlew check :bowerInit UP-TO-DATE :nodeSetup UP-TO-DATE :bowerDependencies UP-TO-DATE :bowerConfig :bowerComponents UP-TO-DATE :bowerInstall UP-TO-DATE :compileJava UP-TO-DATE :compileGroovy UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :karmaInit UP-TO-DATE

Is using javascript setters and getter properties to watch for changes a bad idea?

守給你的承諾、 提交于 2020-01-14 03:24:05
问题 Using Object.create one can define setter and getter methods in javascript. o = Object.create(Object.prototype, { fooBar: { get: function() { return "Meh" }, set: function(value) { console.log(value) } } }); console.log(o) will always return Meh, and doing o = "Heyo" would only output the new value directly without changing o . Is there any reason as to why I should not use, or rely on this behavior to trigger events? What about two-way binding frameworks like angular and ember, do they make

How to test John papa vm.model controllers and factories unit testing with jasmine?

梦想与她 提交于 2020-01-14 02:08:32
问题 Ive been using John Papa's style guide for my angular apps and Im just starting to get into the testing. However I can't seem to find any good documentation regarding testing the style with mocha, chai, and jasmine. Here is an example of one of my controllers (function () { 'use strict'; angular.module('app').controller('appController', appControllerFunction); function appControllerFunction($scope, $rootScope, $location, dataService, dataFactory) { var vm = this; function getData() { vm.data